题目描述 小可非常喜欢记忆英语单词,但是他有一个强迫症,他接受不了一个词里同时混合有大写英文字母和小写英文字母,因此需要你帮忙把他要看的英文单词进行大小写转换,但因时间有限只能尽可能少的改变单词中的大小写。 若该词中大写英文字母数量多,则将该词转为大写。 若该词中小写英文字母数量多,则将该词转为小写。 若该词中大小写英文字母数量相同则该词转小写。 输入格式 输入仅一行,是你需要帮忙修改的单词,给定的单词仅由英文字母构成,长度不超过 1 � 6 1e6 1 � 6 1e6 指的是 10的六次方( 1 0 6 10 6 ) 输出格式 输出仅一行,为修改后的单词c++
时间: 2024-04-14 20:32:07 浏览: 23
#include <iostream>
#include <string>
using namespace std;
string convertWord(string word) {
int countUpper = 0, countLower = 0;
for (int i = 0; i < word.length(); i++) {
if (isupper(word[i])) {
countUpper++;
} else {
countLower++;
}
}
if (countUpper > countLower) {
// Convert word to uppercase
for (int i = 0; i < word.length(); i++) {
word[i] = toupper(word[i]);
}
} else {
// Convert word to lowercase
for (int i = 0; i < word.length(); i++) {
word[i] = tolower(word[i]);
}
}
return word;
}
int main() {
string word;
cin >> word;
string convertedWord = convertWord(word);
cout << convertedWord << endl;
return 0;
}