文章

39

粉丝

45

获赞

0

访问

8.5k

头像
手机键盘 题解:为什么牛客网能过和这个网站过不了
P1157 清华大学上机题
发布于2024年3月9日 23:24
阅读数 228

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int eachtime[26]={1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,4,1,2,3,1,2,3,4};
int gorup[26]= {1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,6,7,7,7,8,8,8,8};

int main()
{
    char s[100];
    while(gets(s))
    {
        int sum=0;
        char pre=‘a’;
        for(int i=0;i<strlen(s);i++){
            if(gorup[s[i]-'a']==gorup[pre-'a']) sum+=2;
            sum+=eachtime[s[i]-'a'];
            pre=s[i];

        }

        printf("%d\n",sum);


    }
}
在本地比如说bob是7,但是在线输出结果是9

登录查看完整内容


登录后发布评论

2 条评论
snake
2024年3月9日 23:48

要注意gets这个函数会读空行,用gets的时候要小心,如果读入的字符串是空的就不输出。

赞(0)

xjnotywlq : 回复 snake: 确实是啊,加了if(strlen(s)==0)break;就能过了

2024年3月10日 13:53