P5733 【深基6.例1】自動修正 ——字符串大小寫轉換

這裏是引用

AC代碼(一):

#include<bits/stdc++.h>

using namespace std;

int main(){
	string s;
	getline( cin, s );
	for(int i=0; i<s.size(); i++){
		if(s[i] >= 'a' && s[i] <= 'z'){
			s[i] -= 32;
		}
	}
	cout << s <<endl;
	return 0;
}

AC代碼(二):

#include<bits/stdc++.h>

using namespace std;

int main(){
	string s;
	getline(cin, s);
	for(int i=0; i<s.length(); i++){
		int temp = s[i];
		if(temp>=97 && temp<=123){
			printf("%c", temp-32);
		}else{
			printf("%c", temp);
		}
	} 
	return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章