字符串的长度

Problem J: 字符串的长度
Time Limit: 1 Sec Memory Limit: 16 MB
Submit: 16458 Solved: 7179
[Submit][Status]
Description
输入一些字符串,输出它们的长度。

Input
输入为多行。第一行N>0表示有N个测试用例,后面有N行,每行包含一个字符串(不超过1000个字符)。

Output
输出为多行,每行对应于一个测试用例。每行的格式为:

case i:length=j.

其中i表示测试用例编号(从1开始),j表示相应的字符串长度。

Sample Input
4
I love China!
Do you want to pass this examination?
You will succeed finially!
Wish you succeed!
Sample Output
case 1:length=13.
case 2:length=37.
case 3:length=26.
case 4:length=17.
HINT
用scanf()读取整数后,第一行的换行符需要处理。可以用文件测试出这个问题来。

Append Code

#include<stdio.h>
#include<string.h>
int main()
{
    int n,i,a;
    char s[1001];
    scanf("%d",&n);
    getchar();//吃掉一个字符
    for(i=1;i<=n;i++)
    {
        gets(s);//字符串输入专用函数
        a=strlen(s);
        printf("case %d:length=%d.\n",i,a);
    }
    return 0;
}

scanf无法输入空白符

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值