玲珑学院OJ 1005 - Spoon Devil's RP Test(求余问题)

题目链接: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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值