一只猪


私信TA

用户名:TuT99

访问量:6638

签 名:

拥有良好的积累,并且一直在路上,我相信自己有无限的可能

等  级
排  名 74
经  验 9588
参赛次数 6
文章发表 66
年  龄 21
在职情况 学生
学  校 哔哩哔哩大学
专  业 计算机科学与技术

  自我简介:

代码解析:


参考代码:

#include <iostream>

#include <string>

#include <cctype>

using namespace std;


string formatMedicineName(const string& medicineName) {

    string formattedName = medicineName;

    if (!formattedName.empty()) {

        formattedName[0] = toupper(formattedName[0]); // 将第一个字符转换为大写

        for (int i = 1; i < formattedName.length(); i++) {

            formattedName[i] = tolower(formattedName[i]); // 其他字符转换为小写

        }

    }

    return formattedName;

}


int main() {

    int n;

    cin >> n;


    for (int i = 0; i < n; i++) {

        string medicineName;

        cin >> medicineName;


        string formattedName = formatMedicineName(medicineName);

        cout << formattedName << endl;

    }


    return 0;

}


 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区