2 条题解

  • 1
    @ 2026-8-20 10:06:50
    #include <string>
    using namespace std;
    
    int main() {
        string s;
        cin >> s;
        while (s.size() % 4 != 0)
            s = "0" + s;
    
        int n = s.size() / 4;
        string names[] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
        string units[] = {"", "wan", "yi"};
    
        string result;
        bool started = false;
    
        for (int sec = 0; sec < n; sec++) {
            int digits[4];
            for (int i = 0; i < 4; i++)
                digits[i] = s[sec * 4 + i] - '0';
    
            bool sec_started = false;
            int last_pos = -1;
    
            for (int i = 0; i < 4; i++) {
                int d = digits[i];
                if (d == 0) continue;
    
                bool need_ling = false;
                if (sec_started) {
                    if (last_pos < i - 1)
                        need_ling = true;
                } else {
                    if (started && i > 0)
                        need_ling = true;
                }
    
                if (need_ling) {
                    if (!result.empty()) result += " ";
                    result += "ling";
                }
    
                if (!result.empty()) result += " ";
                if (i == 0)
                    result += names[d] + " qian";
                else if (i == 1)
                    result += names[d] + " bai";
                else if (i == 2) {
                    if (d == 1 && !sec_started && !need_ling)
                        result += "shi";
                    else
                        result += names[d] + " shi";
                } else
                    result += names[d];
    
                sec_started = true;
                started = true;
                last_pos = i;
            }
    
            if (sec_started) {
                int unit_idx = n - 1 - sec;
                if (unit_idx > 0) {
                    if (!result.empty()) result += " ";
                    result += units[unit_idx];
                }
            }
        }
    
        if (result.empty())
            result = "ling";
    
        cout << result << endl;
        return 0;
    }
    
    
    
    • 1
      @ 2026-8-20 10:06:32
      #include <string>
      using namespace std;
      
      int main() {
          string s;
          cin >> s;
          while (s.size() % 4 != 0)
              s = "0" + s;
      
          int n = s.size() / 4;
          string names[] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
          string units[] = {"", "wan", "yi"};
      
          string result;
          bool started = false;
      
          for (int sec = 0; sec < n; sec++) {
              int digits[4];
              for (int i = 0; i < 4; i++)
                  digits[i] = s[sec * 4 + i] - '0';
      
              bool sec_started = false;
              int last_pos = -1;
      
              for (int i = 0; i < 4; i++) {
                  int d = digits[i];
                  if (d == 0) continue;
      
                  bool need_ling = false;
                  if (sec_started) {
                      if (last_pos < i - 1)
                          need_ling = true;
                  } else {
                      if (started && i > 0)
                          need_ling = true;
                  }
      
                  if (need_ling) {
                      if (!result.empty()) result += " ";
                      result += "ling";
                  }
      
                  if (!result.empty()) result += " ";
                  if (i == 0)
                      result += names[d] + " qian";
                  else if (i == 1)
                      result += names[d] + " bai";
                  else if (i == 2) {
                      if (d == 1 && !sec_started && !need_ling)
                          result += "shi";
                      else
                          result += names[d] + " shi";
                  } else
                      result += names[d];
      
                  sec_started = true;
                  started = true;
                  last_pos = i;
              }
      
              if (sec_started) {
                  int unit_idx = n - 1 - sec;
                  if (unit_idx > 0) {
                      if (!result.empty()) result += " ";
                      result += units[unit_idx];
                  }
              }
          }
      
          if (result.empty())
              result = "ling";
      
          cout << result << endl;
          return 0;
      }
      
      
      
      • 1

      信息

      ID
      1133
      时间
      1000ms
      内存
      128MiB
      难度
      10
      标签
      递交数
      2
      已通过
      2
      上传者