• Problem A. Speaking in Tongues


    字母替换

    // Test.cpp : Defines the entry point for the console application.
    //
    
    //#include "stdafx.h"
    #include <iostream>
    #include <vector>
    #include <list>
    #include <string>
    #include <map>
    
    using namespace std;
    
    
    int main()
    {
        map<char, char> chatMap;
        chatMap.insert(make_pair('a', 'y'));
        chatMap.insert(make_pair('b', 'h'));
        chatMap.insert(make_pair('c', 'e'));
        chatMap.insert(make_pair('d', 's'));
        chatMap.insert(make_pair('e', 'o'));
        chatMap.insert(make_pair('f', 'c'));
        chatMap.insert(make_pair('g', 'v'));
        chatMap.insert(make_pair('h', 'x'));
        chatMap.insert(make_pair('i', 'd'));
        chatMap.insert(make_pair('j', 'u'));
        chatMap.insert(make_pair('k', 'i'));
        chatMap.insert(make_pair('l', 'g'));
        chatMap.insert(make_pair('m', 'l'));
        chatMap.insert(make_pair('n', 'b'));
        chatMap.insert(make_pair('o', 'k'));
        chatMap.insert(make_pair('p', 'r'));
        chatMap.insert(make_pair('q', 'z'));
        chatMap.insert(make_pair('r', 't'));
        chatMap.insert(make_pair('s', 'n'));
        chatMap.insert(make_pair('t', 'w'));
        chatMap.insert(make_pair('u', 'j'));
        chatMap.insert(make_pair('v', 'p'));
        chatMap.insert(make_pair('w', 'f'));
        chatMap.insert(make_pair('x', 'm'));
        chatMap.insert(make_pair('y', 'a'));
        chatMap.insert(make_pair('z', 'q'));
    
        FILE* pf = fopen("out.txt", "w+");
        int caseNum = 0;
        scanf("%d\n", &caseNum);
    
        char* s = (char*)malloc(10000 * sizeof(char));
        string* t = new string[caseNum];
        memset(s, 0, 10000 * sizeof(char));
        for(int i = 0; i<caseNum; ++i)
        {
            memset(s, 0, 10000 * sizeof(char));
            t[i] = "";
            gets(s);
            int len = strlen(s);
            
            map<char, char>::iterator iter;
            for(int j = 0; j<len; ++j)
            {
                if(s[j] == ' ')
                {
                    t[i].push_back(' ');
                    continue;
                }
                iter = chatMap.find(s[j]);
                if(iter != chatMap.end())
                    t[i].push_back(iter->second);
            }
            
            
        }
    
        for(int k = 0; k<caseNum; ++k)
        {
            memset(s, 0, 10000 * sizeof(char));
            sprintf(s, "Case #%d: %s\n", k+1, t[k].c_str());
            fputs(s, pf);
        }
    
        free(s);
        delete [] t;
    
        return 0;
    }
  • 相关阅读:
    使用NPOI将多张图片导入execl
    Oracle计算时间差函数
    Oracle_spatial的函数介绍[转]
    FDO error:Failed to label layer(XXX) for class Default
    您属于哪个版本的程序员[转]
    关于oracle-12514错误的修改方法
    ArcGis在Oracle中常用的sql
    读取XML绑定TreeNode
    HTML中图片热区的使用
    如何查看目前正在使用的Windows10是哪个版本?
  • 原文地址:https://www.cnblogs.com/dangerman/p/2959504.html
Copyright © 2020-2023  润新知