题目链接:http://www.codeforces.com/problemset/problem/131/A
题意:字符串大小写转换。
C++代码:
#include <cstdio> #include <cstring> char s[110]; bool islow(char c) { return c >= 'a' && c <= 'z'; } char up(char c) { return c - 32; } char low(char c) { return c + 32; } bool check() { char *t = s; t ++; while (*t) { if (islow(*t)) return true; t ++; } return false; } int main() { scanf("%s", s); if (check()) { puts(s); } else { char *t = s; while (*t) { if (islow(*t)) putchar(up(*t)); else putchar(low(*t)); t ++; } } return 0; }