南阳理工 457 大小写互换

#include<stdio.h>
#include<string.h>
int main(){
int n,i;
char a[101];
scanf("%d",&n);
getchar();            //此题要有getchar(),否则打完100后会自动输入字符。
while(n--){
gets(a);
for(i=0;i<strlen(a);i++){
if(a[i]<='Z'&&a[i]>='A'){
a[i]+=32;                //大小写之间asc2码的数值相差32,其中大写比小写要小。
}
else{
a[i]-=32;
}
}
for(i=0;i<strlen(a);i++){
printf("%c",a[i]);
}
printf("\n");
}
return 0;

}


优秀代码

01. #include<stdio.h>
02. int main()
03. {
04. int a,b,c,n;
05. char x;
06. scanf("%d",&n);
07. getchar();
08. while(n--)
09. {
10. while(scanf("%c",&x)&&x!='\n')
11. {
12. if(x>=97&&x<=122) printf("%c",x-32);
13. else if(x<=90&&x>=64) printf("%c",x+32);
14. }
15. printf("\n");
16. }
17. }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值