1259 通俗易懂的大数据

1259.Problem G. play the guitar

Time Limit: 1000 MS    Memory Limit: 32768 KB
Total Submission(s): 17    Accepted Submission(s): 9

Description

lmh like playing the guitar, but he don’t satisfy others’ GTP. He want to write guitar score by himself. And he don’t want to use 53231323, it’s boring! He want to find a new rhythm. So he come up with a idea: get a GTP by computer and math. So he choose “n^k” this expression. But we know, the guitar just have only six chords. So we have to change all 7,8,9 to 1,2,3(7 to 1, 8 to 2, 9 to 3, 0 means open string).

Now give you n and k, can you give lmh a prefect GTP?

Input

Input contains multiple test cases.

Each test case starts with two numbers n and k (0 < N <= 300, 0 < k <= 300).

Output

Calculate n^k and change all 7,8,9 to 1,2,3(7 to 1, 8 to 2, 9 to 3).

Sample Input

2 2
2 4
2 7

Sample Output

4

16

122

思路:将2的2次方, 2的4次方, 2 的7次方中的7变成1, 8变成2, 9变成3

一般人会用java处理 但在这里我选用了c

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
using namespace std;
int a[100005];
int b[100005];
int h[100005];
int main()
{
     char s[100000];
    while( scanf("%s", s)!= EOF )
    {int n , k , i, j ;
    scanf("%d", &k);
    int h1 = strlen ( s ); 
    int cnt1 = 1;
    int cnt2 = 1;
    for( i = h1-1; i>=0; i--)
    {
        a[cnt1++] = s[i] -'0';
        b[cnt2++] = s[i] - '0';///从个位开始存储
    }
    int time = 0;
    while( time < k-1 )
    {
        time++;
        for( i = 1; i<cnt1; i++)
        {
            for( j =1; j<cnt2; j++)
            {
                h[i+j-1] = h[i+j-1] + a[i]*b[j];
                h[i+j]  =h[i+j]+ h[i+j-1]/10;
                h[i+j-1] = h[i+j-1]%10;
            }
        }
        if( h[i+j-2] != 0)
        cnt2 = cnt2+cnt1 - 1;
        else
            cnt2 = cnt2+cnt1-2;
        for( i = 1 ; i< cnt2; i++)
        {
            b[i] = h[i];
           //printf("%d", h[i]);///不断更新b, a不变
        }
        memset( h, 0 ,sizeof( h ));
    }
    //for( i = cnt2-1; i>=1; i--)
        //printf("%d", b[i]);
   // printf("\n");
    for( i = cnt2- 1; i>=1; i--)
    {
        if( b[i] == 7 )
            b[i] = 1;
        else if( b[i] == 8)
        b[i] = 2;
        else if( b[i] == 9)
        b[i] = 3;
        printf("%d", b[i]);
    }
    printf("\n");
    memset( s, 0 ,sizeof( s));
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值