C++ 字符串首字母大写,其余小写转换程序
C++ 字符串首字母大写,其余小写转换程序
算法 1 (模拟)
时间复杂度: O(n)
思路:
按照题目要求进行模拟即可。
C++ 代码:
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
if (s.size() > 0) {
s[0] = toupper(s[0]);
for (int i = 1; i < s.size(); ++i) {
s[i] = tolower(s[i]);
}
}
cout << s << endl;
return 0;
}
原文地址: https://www.cveoy.top/t/topic/oGva 著作权归作者所有。请勿转载和采集!