top1编程
← 返回题目
题解

【基础】最长姓名的汉语拼音

1 条题解

  • 0
    @ 2026-7-29 0:19:18
    #include <iostream>
    #include <string>
    #include <vector>
    using namespace std;
    
    int main() {
        int n;
        cin >> n;
    
        string best = "";  // 初始为空
    
        for (int i = 0; i < n; i++) {
            string s;
            cin >> s;
    
            // 如果当前字符串更长,或者长度相同但字典序更大,则更新
            if (s.length() > best.length() || 
                (s.length() == best.length() && s > best)) {
                best = s;
            }
        }
    
        cout << best << endl;
    
        return 0;
    }
    
    • 1