送快递

来源:互联网 发布:如何购买空间和域名 编辑:程序博客网 时间:2024/04/27 16:46

送快递
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description

最近 bLue 买了很多快递,送快递的艰巨任务就落在了快递小哥头上。
已知快递小哥和 bLue 之间的路可以看做一行字符串,而快递小哥比较奇葩,不按套路走,他从 ‘s’ 处出发,每次移动 c 个单位的距离,送到 bLue 所在的位置 ‘e’。
假设快递小哥每次移动 c 个单位后到达的位置上的字符为 s[i],那么此次移动所耗费的体力为 s[i] - ‘a’。快递小哥想知道从 ‘s’ 出发到 ‘e’ 需要耗费多少体力?
Input

输入数据有多组(数据组数不超过 50),到 EOF 结束。
每组输入包含一行,为一个不含空格且长度不超过 1000 的字符串 str 和快递小哥每次移动的距离 c (c 大于 0 且小于字符串长度)。
保证字符串里只包含一个 ‘s’ 和一个 ‘e’,且只包含小写字母。
Output

对于每组数据,输出一个数字,如果快递小哥能把快递送到 bLue 手上,则输出快递小哥总共需要耗费的体力。如果无法到达 ‘e’,则输出 “QAQ”(输出不包含引号)。
Example Input

se 1
abscdef 3
sdde 1
asaae 2
aebcdsz 2
Example Output

4
4
10
QAQ
6
Hint

Author

Foxz

#include <stdio.h>#include <string.h>int main(){    int i, l, c, qs, qe, t, k, sum;    char ch[1004];    while(scanf("%s", ch) != EOF)    {        scanf("%d", &c);        sum = 0;        l = strlen(ch);        for(i = 0; i < l; i++)        {            if(ch[i] == 's')                qs = t = i;            else if(ch[i] == 'e')                qe = k = i;        }        if(qs < qe)        {            while(t != k&&(qe-qs)%c == 0)            {                t += c;                sum += ch[t] - 'a';            }        }        if(qs > qe)        {            while(t != k&&(qs-qe)%c == 0)            {                t -= c;                sum += ch[t] - 'a';            }        }        if(t == k)            printf("%d\n", sum);        else            printf("QAQ\n");    }    return 0;}/***************************************************User name: jk160630徐如意Result: AcceptedTake time: 0msTake Memory: 104KBSubmit time: 2017-01-10 13:58:07****************************************************/
1 0
原创粉丝点击