3410 - 考试三字符操作
时间限制 : 1 秒
内存限制 : 128 MB
输入N个字母字符串,要求小写变大写,大写变小写输出,并统计其中大写字母的个数,小写字母的个数输出;(N<=100)
题目输入
输入包含大小写字母的字符串HElloWorld
题目输出
将大写字母转换成小写,小写反之,输出;并输出转换后的大写字母个数以及小写字母个数
输入/输出样例
输入格式
HElloWorld
输出格式
heLLOwORLD 7 3
C语言解答
#include<stdio.h> #include<string.h> int main() { char str[80]; int len,i,a=0,b=0; gets(str); len=strlen(str); for(i=0;i<len;i++) { if (('A'<=str[i])&&(str[i]<='Z')) { str[i]=str[i]+32,a++; } else if (('a'<=str[i])&(str[i]<='z')) { str[i]=str[i]-32,b++; } } puts(str); printf("%d %d",b,a); return 0; }
C++解答
#include <iostream> #include <string> using namespace std; int main() { int big = 0, small = 0; string s; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] >= 'A' && s[i] <= 'Z') { small++; s[i] += 32; } else { big++; s[i] -= 32; } } cout << s << endl; cout << big << ' ' << small << endl; return 0; }