Message Decowding(2716)

Problem Description
The cows are thrilled because they've just learned
about encrypting messages. They think they will be able to use secret messages
to plot meetings with cows on other farms.
Cows are not known for their
intelligence. Their encryption method is nothing like DES or BlowFish or any of
those really good secret coding methods. No, they are using a simple
substitution cipher.
The cows have a decryption key and a secret message.
Help them decode 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 in place.
Input text is in upper or lower case, both decrypt using
the same decryption key, keeping the appropriate case, of course.
 
Input
* Line 1: 26 lower case characters representing the
decryption key
* Line 2: As many as 80 characters that are the message to
be decoded
 
Output
* Line 1: A single line that is the decoded message. It
should have the same length as the second line of input.
 
Sample Input
eydbkmiqugjxlvtzpnwohracsf Kifq oua zarxa suar bti yaagrj fa xtfgrj
 
Sample Output
Jump the fence when you seeing me coming
 
 
题目解说:依照加密的26个字符,依次查找a b c d ......,最后输出。
程序:

#include<iostream>
#include<string>
#include<vector>
using namespace std;
typedef struct
{
 char x,y1,y2;
}zf;
void f(const vector<zf> v,string s1)
{
     vector<char> re;
     for(int i=0;i<s1.length();i++)
 {
  if((s1[i]>='A'&&s1[i]<='Z')||(s1[i]>='a'&&s1[i]<='z'))
  {
       for(int j=0;j<v.size();j++)
      {        
        zf ju=v[j];
        if(s1[i]==ju.y2||s1[i]==ju.y1)
       {    
         if(s1[i]>='A'&&s1[i]<='Z')
          re.push_back(ju.x-32);
         else
          re.push_back(ju.x);
     break;
      }
     }
  }
  else 
  re.push_back(s1[i]);
 }
 vector<char>::iterator it=re.begin();
 while(it!=re.end())
  cout<<*it++;
}

int main()
{
 //freopen("in.txt","r",stdin);
 char s[27],s1[10000];
 vector<zf> v;
 zf w;
 while(gets(s))
 { 
  gets(s1);
  for(int i=0;i<sizeof(s);i++)
  {
   w.x=s[i];w.y1='a'+i;w.y2='A'+i;
   v.push_back(w);
  }
  f(v,s1);
  v.clear();
  cout<<endl;
 }
 return 0;
}


 

你可能感兴趣的:(递归,ACM,message,杭电,2716,Decowding)