题目链接:http://www.ifrog.cc/acm/problem/1005
1005 - Spoon Devil’s RP Test
Time Limit:1s Memory Limit:32MByte
Submissions:83Solved:49
DESCRIPTION
Spoon Devil finds a way to test one person’s RP: He defines ‘a’ = 1, ‘b’ = 2^2, … ‘z’ = 26^2, so the value of ‘abc’ is 149, and the RP of ‘abc’ is the value of ‘abc’ mod 101. So the RP of ‘abc’ is 48.
INPUT
The first line is a single integer
T
T which is the number of test cases.
Each case only contains a name, which only contains lower-case letter.
OUTPUT
For each test case, output is the RP of the name in one line.
SAMPLE INPUT
1
spoondevil
SAMPLE OUTPUT
78
SOLUTION
“玲珑杯”acm比赛-试运行赛
【题意】给你每个字母的RP值,让你算出总的RP值,然后对101求余。
【思路】每加一个字母求一次余,暴力扫一遍就OK了。
下面是AC代码:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
char a[105];
int num(int n)//计算数字位数
{
int sum=0;
while(n)
{
n/=10;
sum++;
}
return sum;
}
int power(int n)//计算10的次幂
{
int ans=1;
for(int i=0;i<n;i++)
{
ans*=10;
}
return ans;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",a);
int len=strlen(a);
int rp=0,l=0;
for(int i=0;i<len;i++)
{
rp=rp*power(num((a[i]-'a'+1)*(a[i]-'a'+1)))+(a[i]-'a'+1)*(a[i]-'a'+1);
rp%=101;
}
printf("%d\n",rp);
}
return 0;
}