题解:P13311 [GCJ 2012 Qualification] Speaking in Tongues

· · 题解

题目传送门 P13311

题解开头先宣传一下我的博客

这是一道非常简单的字符串题,如果我们想要解决这个问题,就需要把Googlerese语言转换为正常英语

通过题目中举的例子我们可以得出下图:

AC代码:

#include <iostream>//华丽的开头
#include <string>
using namespace std;
int main()
{
//按顺序定义Googlerese到普通字母的数组
    char zimu[30]={'y','h','e','s','o','c','v','x','d','u','i','g','l','b','k','r','z','t','n','w','j','p','f','m','a','q'};
    int t;
    cin>>t;
    cin.ignore();//用来忽略换行符,本蒟蒻就是忘写WA了
    for(int i=1;i<=t;i++)
    {
        string s;
        getline(cin,s);//getline
        string ans;
        for(char c:s)
        {
            if(c==' ')
            {
                ans+=' ';
            }
            else
            {
                ans+=zimu[c-'a'];//将Googlerese语言字符转换为现实字符
            }
        }
        cout<<"Case"<<" #"<<i<<": "<<ans<<endl;
    }
    return 0;//隆重的结尾
}

重要提醒:

\color{red}题解仅供学习参考使用

这个代码非常简单高效,易理解,时间复杂度为O(N) 。

望通过