大数模余

题目描述:
    A lot of people have played fortune Test(or called RP Test) before. Let ’ s create a new Test below.

Suppose the worth of a=1, b=4,c=9 … and z=26^2. Then abc can describe as 149,and abd describe as

1416. As it is too large ,we take it mod 101 as ours fortune worth. S o abd has only 2 RP. Now I give you

a name, please tell me the worth of it.


输入

The first line of the input contains the number of test cases in the file. Each test case that follows

consists of one lines. each case contains only one string s specifying a person ’ s name, which only

contains lower-case .


输出
For each test case, print a line contains the answer.


样例输入
1
a

样例输出
1

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
const int maxn = 10000;
char str[maxn];
int a[maxn];
int T;

void translate(){
    stack<int> s;
    int point = 0;
    int len = strlen(str);
    int x;
    for(int i = 0; i<len; i++){
        int mid = str[i]-'a'+1;
        int tmp = mid * mid;
        while(tmp) {        ///把数值X分解并存入数组a中。
            x = tmp%10;
            s.push(x);
            tmp = tmp/10;
        }
        int counter = (int)s.size();
        for(int j=1; j<=counter; j++) {
            a[point++] = s.top();
            s.pop();
        }
    }
}

int work() {
    int ans = 0;
    for(int i = 0; a[i]>0; i++) {
        ans = (ans*10+a[i])%101;
    }
    return ans;
}

int main()
{
    scanf("%d", &T);
    while(T--) {
        scanf("%s", str);
        getchar();
        translate();
        int res = work();
        printf("%d\n", res);
        memset(a, 0, sizeof(a));
        memset(str, 0, sizeof(str));
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值