#36568: C++簡單寫法


a155328@stdmail.nssh.ntpc.edu. ... (王宥崴)

學校 : 南山中學
編號 : 204604
來源 : [1.34.242.127]
最後登入時間 :
2024-11-03 19:52:55
f515. 英文縮寫 (Abbreviation) -- TOI練習賽202012新手組第3題 | From: [114.44.102.202] | 發表日期 : 2023-07-24 14:13

#include <iostream>
#include <string>
using namespace std;
int main() {
  string input;
  getline(cin, input);
  string small = "";
  string word = "";
  for (char c : input) {
    if (c == ' ') {
      if (word == "for" || word == "FOR" || word == "For")
        small += "4";
      else if (word == "to" || word == "TO" || word == "To")
        small += "2";
      else if (word == "and" || word == "AND" || word == "And")
        small += "n";
      else if (word == "you" || word == "YOU" || word == "You")
        small += "u";
      else {
        if (word[0] >= 'a' && word[0] <= 'z') {
          word[0] = word[0] - 'a' + 'A';
        }
        small += word[0];
      }

      word = "";
    } else {
      word += c;
    }
  }

  if (word == "for" || word == "FOR" || word == "For")
    small += "4";
  else if (word == "to" || word == "TO" || word == "To")
    small += "2";
  else if (word == "and" || word == "AND" || word == "And")
    small += "n";
  else if (word == "you" || word == "YOU" || word == "You")
    small += "u";
  else {
    if (word[0] >= 'a' && word[0] <= 'z') {
      word[0] = word[0] - 'a' + 'A';
    }
    small += word[0];
  }

  cout << small << endl;

  return 0;
}

 
ZeroJudge Forum