字符串:zoj 1831 Substitution Cypher

【转】http://hi.baidu.com/sunkehappy/blog/item/c1a400cafe94294cf21fe7a6.html

 

 

/*  字符串简单题
*   2009-09-24 16:28:42 Accepted  1831 C++ 0 184 祝你好运!
*   里面有比较诡异的地方,大概是原码和密码中有空格对应关系,
*   所以必须用getline或者gets之类的读取整行的函数读取,不然会WA 。
*/

 

#include <iostream>
#include <map>
#define  DEBUG 1
using namespace std ;

map<char,char> cypher ;

int main()
{
    #if DEBUG
    freopen("C:\\Documents and Settings\\Administrator\\桌面\\in.txt","r",stdin) ;
    freopen("C:\\Documents and Settings\\Administrator\\桌面\\out.txt","w",stdout) ;
    #endif
    
    char ch ;
    int i ;
    string from, to ;
    getline( cin, from ) ;
    getline( cin, to ) ;
    cout << to << endl << from << endl ;
    for( i=0; i<from.size(); ++i ){
        cypher[ from[i] ] = to[i] ;
    }
    while( EOF != scanf("%c", &ch ) ){
        if( cypher.count( ch ) )
            printf("%c", cypher[ch] ) ;
        else
            printf("%c", ch ) ;
    }
    return 0 ;
}

 

你可能感兴趣的:(cypher)