codeforces 131-A. cAPS lOCK

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_39651984/article/details/79130789

题目连接

我没看懂题目--

1.如果字符串全是大写,则输出全部小写

2.如果第一个字母小写,后面全是大写,输出第一个字母大写,后面全是小写

3.一个字母,输出大写

其他的不动输出

int main(int argc, char const *argv[])
{
	string str; cin >> str; int len = str.length();
	int lnum = 0, unum = 0; //小写字母的数量,大写字母的数量
	_for(i,0,len){
		if(isupper(str[i])) unum++;
		else lnum++;
	}
	if(unum == len){
		_for(i,0,len) str[i] = tolower(str[i]);
	}else if(len >= 2 && lnum == 1 && islower(str[0])){
		_for(i,0,len){
			if(i == 0) str[i] = toupper(str[i]);
			else str[i]= tolower(str[i]);
		}
	}else if(len == 1 && islower(str[0])) str[0] = toupper(str[0]);

	cout << str << endl;
	

  return 0;
}




猜你喜欢

转载自blog.csdn.net/qq_39651984/article/details/79130789