poj2141(字符串)

来源:互联网 发布:什么是淘宝同步单 编辑:程序博客网 时间:2024/05/21 14:44

http://poj.org/problem?id=2141

MessageDecowding
Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 10477Accepted: 5772

Description

The cows arethrilled because they've just learned about encrypting messages.They think they will be able to use secret messages to plotmeetings with cows on other farms.

Cows are not known for their intelligence. Their encryption methodis nothing like DES or BlowFish or any of those really good secretcoding methods. No, they are using a simple substitutioncipher.

The cows have a decryption key and a secret message. Help themdecode it. The key looks like this:
        yrwhsoujgcxqbativndfezmlpk

Which means that an 'a' in the secret message really means 'y'; a'b' in the secret message really means 'r'; a 'c' decrypts to 'w';and so on. Blanks are not encrypted; they are simply kept inplace.

Input text is in upper or lower case, both decrypt using the samedecryption key, keeping the appropriate case, ofcourse.

Input

* Line 1: 26 lowercase characters representing the decryption key

* Line 2: As many as 80 characters that are the message to bedecoded

Output

* Line 1: A singleline that is the decoded message. It should have the same length asthe second line of input.

Sample Input

eydbkmiqugjxlvtzpnwohracsfKifq oua zarxa suar bti yaagrj fa xtfgrj

Sample Output

Jump the fence when you seeing me coming

Source

USACO 2003 March Orange
题意:第一行对应的是字符串加密的方式,第二行对应的是要加密的字符串(按照第一行给的加密方式加密)。
其中第一行加密方式是第一个对应a,第二个对应b,第三个对应c,以此类推第26个对应z。。
要你输出第二行通过加密后得到的字符串。。。
思路:关键是要找到第二行的字符在第一行字符串中第几个就可以了。。。。这句最关键好好理解下。。
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define maxn 1010
char s1[maxn],s2[maxn];
int main()
{
 while(gets(s1)!='\0')
 {
  gets(s2);
  int len=strlen(s2);
  int i;
  for(i=0;i<len;i++)
  {
   if(s2[i]=='')
    continue;
   elseif(isupper(s2[i]))
    s2[i]=toupper(s1[s2[i]-'A']);
   else
    s2[i]=s1[s2[i]-'a'];
  }
  printf("%s\n",s2);
 }
 return 0;
}