zoukankan      html  css  js  c++  java
  • 加密(字符串处理)问题

    问题:Cipher text
    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

    Plain text
    V W X Y Z A B C D E F G H I J K L M N O P Q R S T U

    Input
    Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. All characters will be uppercase.

    A single data set has 3 components:

    Start line - A single line, "START"

    Cipher message - A single line containing from one to two hundred characters, inclusive, comprising a single message from Caesar

    End line - A single line, "END"

    Following the final data set will be a single line, "ENDOFINPUT".
     
    Output
    For each data set, there will be exactly one line of output. This is the original message by Caesar.
     
    Sample Input
    START NS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX END START N BTZQI WFYMJW GJ KNWXY NS F QNYYQJ NGJWNFS ANQQFLJ YMFS XJHTSI NS WTRJ END START IFSLJW PSTBX KZQQ BJQQ YMFY HFJXFW NX RTWJ IFSLJWTZX YMFS MJ END ENDOFINPUT
     
    Sample Output
    IN WAR, EVENTS OF IMPORTANCE ARE THE RESULT OF TRIVIAL CAUSES I WOULD RATHER BE FIRST IN A LITTLE IBERIAN VILLAGE THAN SECOND IN ROME DANGER KNOWS FULL WELL THAT CAESAR IS MORE DANGEROUS THAN HE
     
    回答:
    #include<stdio.h>  
    #include<string.h>  
    #include<map>  
    using namespace std;  
    map<char,char>mp;  
    void init()  
    {  
        mp['A']='V';mp['B']='W';mp['C']='X';mp['D']='Y';mp['E']='Z';mp['F']='A';mp['G']='B';mp['H']='C';  
        mp['I']='D';mp['J']='E';mp['K']='F';mp['L']='G';mp['M']='H';mp['N']='I';mp['O']='J';mp['P']='K';  
        mp['Q']='L';mp['R']='M';mp['S']='N';mp['T']='O';mp['U']='P';mp['V']='Q';mp['W']='R';mp['X']='S';  
        mp['Y']='T';mp['Z']='U';  
    }  
     
    int main()  
    {  
        char s1[10]="START",s2[10]="END",s[10000],s3[20]="ENDOFINPUT";  
        int i,j;  
        map<char,char>::iterator  it;  
        init();  
        while(gets(s))  
        {  
            if(strcmp(s,s3)==0) break;  
            while(gets(s))  
            {  
                if(strcmp(s,"END")==0) {break;}  
                for(i=0;i<strlen(s);i++)  
                {  
                      it=mp.find(s[i]);  
                      if(it==mp.end())  
                          printf("%c",s[i]);  
                      else printf("%c",mp[s[i]]);  
                }  
                printf(" ");  
            }  
        }  
        return 0;  
     
    }

  • 相关阅读:
    浏览器之本地缓存存储 localStorage 和 sessionStorage的区别以及用法
    webpack 命令 Module build failed (from ./node_modules/babel-loader/lib/index.js) 错误问题解决方案
    webpack 4 x使用详细
    JS动态判断设备类型为PC或者移动端,然后根据设备加载相应的代码
    自制弹出框所踩的坑
    ant深入浅出(一)ant+xdoclet 生成hibernate配置文件以及实体映射文件
    收费系统
    自学考试 (二)数据结构图
    ORM框架Hibernate (四)MyEclipse Hibernate Tool 逆向生成实体类
    自学考试 (一)如何利用MindManager工具复习
  • 原文地址:https://www.cnblogs.com/benchao/p/4480977.html
Copyright © 2011-2022 走看看