首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

大数模缺

2013-03-19 
大数模余题目描述:A lot of people have played fortune Test(or called RP Test) before. Let ’ s create

大数模余
题目描述:
    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;}

热点排行