Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
把一个字符串里所有的大写字母换成小写字母,小写字母换成大写字母。其他字符保持不变。
Input
输入为一行字符串,其中不含空格。长度不超过80个字符。
Output
输出转换好的字符串。
Sample Input
ABCD123efgh
Sample Output
abcd123EFGH
Hint
Source
**要清楚ASCLL码中大写字母和小写字母的先后顺序
先大写后小写,且大小写相差32;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char a[83];
int n,i,j;
gets(a); //输入字符串;
n = strlen(a); //计算字符串的长度;
for(i=0; i<n; i++)
{
if(a[i]<='z'&&a[i]>='a')
a[i] = a[i]-32; //因为先大写后小写,所以减去32;
else if(a[i]<='Z'&&a[i]>='A')
a[i] = a[i]+32;
}
puts(a); //puts函数为字符串输出函数;
return 0;
}
运行结果:
ABCD123efgh
abcd123EFGH
Process returned 0 (0x0) execution time : 3.683 s
Press any key to continue.