#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;
#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.
}