Problem A: 字符的变化
#include<iostream> using namespace std; class Character { public: char cc; public: Character(char c):cc(c){} //使用 列表的方法给函数赋值更为简洁 Character toUpper() {if(cc>=97&&cc<=122) // ASCII码值:97(A)~122(Z) cc=cc-32; //大写字母与小写字母相差32 65(a)~90(z) return cc;} Character toLower() {if(cc>=65&&cc<=90) cc=cc+32; return cc;} void show(){cout<<cc;} }; int main() { int cases; char c; cin>>cases; cout<<"char"<<" upper"<<" lower"<<endl; for (int i = 0; i < cases; i++) { cin>>c; Character character(c); character.show(); cout<<" "; character.toUpper().show(); cout<<" "; character.toLower().show(); cout<<endl; } }