HDU-2573-Typing

题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=2573

这题把%s与gets()的输入法搞混了一直感觉没有错,就是找不出哪里错了,

题目思路不是很难。

直接看代码

#include<stdio.h>
#include<string.h>
int main(void)
{
char s[10];
int l,i,j,flag;
int t,n;
scanf("%d",&t);
while(t--)
{
flag=0;
j=0;
scanf("%d",&n);
getchar();
while(n--)
{
gets(s);
l=strlen(s);
if(l==1)
{
if(flag)
printf("%c",s[0]-32);
else
printf("%c",s[0]);
}
else if(l==4)
{
flag=!flag;
}
else
{
if(flag)
printf("%c",s[6]);
else
printf("%c",s[6]-32);
}
}
printf("\n");
}
return 0;
}

 

如果熟悉sscanf()的也可以这样做

#include<stdio.h>

#include<string.h>
int main()
{
    int t,n,i,k;
    char a[110][10];
    char b[10],c[10];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        getchar();
        for(i=0;i<n;i++)
        {
             gets(a[i]);
        }
        k=0;
        for(i=0;i<n;i++)
        {
           sscanf(a[i],"%[^ ]",b);
           sscanf(a[i],"%*s%s",c);
           if(strcmp(b,"Caps")==0)
           {
               k++;
               continue;
           }
           else if(strcmp(b,"Shift")==0)
           {
               if(k%2==0)
               printf("%c",c[0]-32);
               else
               printf("%c",c[0]);
           }
           else if(k%2==0)
           printf("%s",b);
           else if(k%2==1)
           printf("%c",b[0]-32);
        }
        printf("\n");
    }
    return 0;
}

转载于:https://www.cnblogs.com/liudehao/p/3964584.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值