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;
}

输入: 一个字符串 s。保证字符串中的字符都是英文字母。

输出: 一个字符串,表示将字符串 s 转换后的结果。

输入样例 1: DABAI

输出样例 1: Dabai

输入样例 2: hetao

输出样例 2: Hetao

C++ 字符串首字母大写,其余小写转换

原文地址: https://www.cveoy.top/t/topic/oGu9 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录