zoukankan      html  css  js  c++  java
  • 【志银】NYOJ《题目490》翻译

    1.题目:翻译

    1.1.题目链接

      http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=490

    1.2.题目内容

    2.解题分析

      题目输入输出格式描述不清晰。

    2.1.分析(1)

      所有数据都完成输入,然后再输出(解法1,内存可能不够(AC通过))

    2.2.分析(2)

      待测数据输完一行立马输出一行结果(解法2,内存够(没通过))

    2.3.总结

      两种写法都写了,最后以第一种输入输出格式通过,后台没有内存超出的数据

    3.解题代码

    3.1.解法1(AC)

    //解法1,内存可能不够,对题意通用性高(AC通过)
    #include<iostream>
    #include<map>
    #include<cstdio>
    using namespace std;
    int main() {
      string s[3005], s0, s1 = "", s2 = "";
      map<string, string> f;
      f["czy"] = "cml";
      cin >> s1;
      while(s2 != "BEGIN") {
        cin >> s1 >> s2;
        f[s2] = s1;
      }
      int n = 0;
      char ch[3005];
      do {
        cin >> s[++n];
        ch[n] = getchar();
      }while(s[n] != "END");
      for(int i = 1; i < n; i++) {
        s0 = "";
        for(int j = 0; j < s[i].size(); j++) {
          if(s[i][j] >= 'a' && s[i][j] <= 'z') {
            s0 += s[i][j];
          } else {
            if(f[s0] != "") cout << f[s0];
            else cout << s0;
            cout << s[i][j];
            s0 = "";
          }
        }
        if(f[s0] != "") cout << f[s0];
        else cout << s0;
        if(ch[i] == '
    ') cout << "
    ";
        else cout << " ";
      }
    }
    

    3.2.解法2(WA)

    //解法2,内存能够,因为题意有歧义可能不能这样解(没通过) 
    #include<iostream>
    #include<map>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int main() {
      string s0, s1 = "", s2 = "";
      map<string, string> f;
      f["czy"] = "cml";
      cin >> s1;
      while(1) {
        cin >> s1 >> s2;
        if(s2 == "BEGIN") break;
        f[s2] = s1;
      }
      char s[3005];
      getchar();
      while(1) {
        gets(s);
        if(s[0] == 'E' && s[1] == 'N' && s[2] == 'D') break;
        s0 = "";
        for(int i = 0; i < strlen(s); i++) {
          if(s[i] >= 'a' && s[i] <= 'z') {
            s0 += s[i];
          } else {
            if(f[s0] != "") cout << f[s0];
            else cout << s0;
            cout << s[i];
            s0 = "";
          }
        }
        cout << endl;
      }
    }
    

    创建日期:2016.09.30

    更新日期:2018.11.05

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    python 可迭代对象与迭代器
    linux与linux远程桌面
    get return value of python in shell
    python反汇编函数字节码
    celery.backends.base.NotRegistered.
    supervisor process management
    Kafka的Log存储解析
    kafka config
    Chanel
    PowerPoint的公式
  • 原文地址:https://www.cnblogs.com/chenzhiyin/p/zain3.html
Copyright © 2011-2022 走看看