[NOIp2012提高组]Vigenère 密码

[NOIp2012提高组_Day1T1]

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 char ch[26][26];
 4 queue<char> q;
 5 string key,s;
 6 int main()
 7 {
 8     for(int i=0;i<26;i++)
 9     {
10         q.push(i);
11     }
12     for(int i=0;i<26;i++)
13     {
14         for(int j=0;j<26;j++)
15         {
16             ch[i][j]=q.front();
17             q.pop();
18             q.push(ch[i][j]);
19         }
20         q.push(q.front());
21         q.pop();
22     }
23     cin>>key>>s;
24     int i=0,j=0;
25     bool flag=false;
26     for(i=0;i<s.size();i++)
27     {
28         flag=false;
29         if(j==key.size()) j=0;
30         if(key[j]>='A'&& key[j]<='Z') key[j]=key[j]-'A'+'a';
31         if(s[i]>='A'&& s[i]<='Z') flag=true;
32         if(flag) 
33         {
34             for(int q=0;q<26;q++)
35             {
36                 if(ch[key[j]-'a'][q]==(s[i]-'A'))
37                 {
38                     cout<<(char)(q+'A');
39                     break;
40                 }
41             }
42         }
43         else 
44         {
45             for(int q=0;q<26;q++)
46             {
47                 if(ch[key[j]-'a'][q]==(s[i]-'a'))
48                 {
49                     cout<<(char)(q+'a');
50                     break;
51                 }
52             }
53         }
54         j++;
55     }
56     return 0;
57 } 
原文地址:https://www.cnblogs.com/__Kgds/p/9467037.html