题解 | #[NOIP2018]标题统计#

[NOIP2018]标题统计

https://www.nowcoder.com/practice/b14b87bc6a4547a6839e0a5867c98dba

emm看了一圈大伙的答案,好像都着重在scanf不能吸收空格或换行的特点上了,但是为什么没人利用一下呢?
个人认为这道题偷跑的方法,应该是C语言代码中最简单的了,代码如下:
#include <stdio.h>
#include <string.h>
int main()
{
    char str[1000];
    int count=0;
    while(scanf("%s",str)!=EOF)
    {
        for(int i=0;i<strlen(str);i++)
        {
            count++;
        }
    }
    printf("%d",count);
    return 0;    
}
全部评论
没有比我更简单的了 #include <stdio.h> #include<string.h> int main() { char str[5]={0}; int count=0; while(scanf("%s",str)==1) { count+=strlen(str); } printf("%d\n",count); }</string.h></stdio.h>
点赞 回复 分享
发布于 2023-12-13 01:24 江西

相关推荐

不愿透露姓名的神秘牛友
昨天 21:05
佬们看看应该怎么改
野猪不是猪🐗:牛客匿名,简历实名,抽象
点赞 评论 收藏
分享
评论
15
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务