CCCherry

导航

凉脾的比赛

A - DRM Messages

DRM Encryption is a new kind of encryption. Given an encrypted string (which we’ll call a DRM message), the decryption process involves three steps: Divide, Rotate and Merge. This process is described in the following example with the DRM message “EWPGAJRB”:

Divide

– First, divide the message in half to “EWPG” and “AJRB”.

Rotate

– For each half, calculate its rotation value by summing up the values of each character (A=0,B=1,,Z=25A=0,B=1,…,Z=25). The rotation value of “EWPG” is 4+22+15+6=474+22+15+6=47. Rotate each character in “EWPG” 4747 positions forward (wrapping from Z to A when necessary) to obtain the new string “ZRKB”. Following the same process on “AJRB” results in “BKSC”.

Merge

– The last step is to combine these new strings (“ZRKB” and “BKSC”) by rotating each character in the first string by the value of the corresponding character in the second string. For the first position, rotating ‘Z’ by ‘B’ means moving it forward 1 character, which wraps it around to ‘A’. Continuing this process for every character results in the final decrypted message, “ABCD”.

Input

The input contains a single DRM message to be decrypted. All characters in the string are uppercase letters and the string’s length is even and 15000≤15000.

Output

Display the decrypted DRM message.

Sample Input 1Sample Output 1
EWPGAJRB
ABCD
Sample Input 2Sample Output 2
UEQBJPJCBUDGBNKCAHXCVERXUCVK
ACMECNACONTEST

 

思路:
  模拟,比赛的时候找了半天的bug,没想到是把i写成l了!!!

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstdio>
 4 #include <string>
 5 using namespace std;
 6 int main()
 7 {
 8     string s;
 9     int a[15005];
10     int s1=0,s2=0;
11     cin>>s;
12     int l=s.size();
13     for(int i=0;i<l;i++)
14     {
15         a[i]=s[i]-'A';    
16     }
17     for(int i=0;i<l/2;i++)
18     {
19         s1+=a[i];
20     }
21     for(int i=l/2;i<l;i++)
22     {
23         s2+=a[i];
24     }
25     s1%=26;
26     s2%=26;
27     for(int i=0;i<l/2;i++)
28     {
29         a[i]+=s1;
30         a[i]%=26;
31     }
32     for(int i=l/2;i<l;i++)
33     {
34         a[i]+=s2;
35         a[i]%=26;
36     }
37     for(int i=0;i<l/2;i++)
38     {
39         a[i]+=a[i+l/2];
40         a[i]%=26;
41         cout<<char(a[i]+'A');
42     }
43     
44     
45 
46     
47 }

B - Game of Throwns


Daenerys frequently invents games to help teach her second grade Computer Science class about various aspects of the discipline. For this week’s lesson she has the children form a circle and (carefully) throw around a petrified dragon egg.


The nn children are numbered from 00 to n1n−1 (it is a Computer Science class after all) clockwise around the circle. Child 00 always starts with the egg. Daenerys will call out one of two things:


  1. a number tt , indicating that the egg is to be thrown to the child who is tt positions clockwise from the current egg holder, wrapping around if necessary. If tt is negative, then the throw is to the counter-clockwise direction.

  2. the phrase undo mm , indicating that the last mm throws should be undone. Note that undo commands never undo other undo commands; they just undo commands described in item 11 above.


For example, if there are 55 children, and the teacher calls out the four throw commands 8 -2 3 undo 2, the throws will start from child 00 to child 33 , then from child 33 to child 11 , then from child 11 to child 44 . After this, the undo 2 instructions will result in the egg being thrown back from child 44 to child 11 and then from child 11 back to child 33 . If Daenerys calls out 00 (or n,n,2n,2nn,−n,2n,−2n , etc.) then the child with the egg simply throws it straight up in the air and (carefully) catches it again.


Daenerys would like a little program that determines where the egg should end up if her commands are executed correctly. Don’t ask what happens to the children if this isn’t the case.


Input


Input consists of two lines. The first line contains two positive integers nn kk (1n301≤n≤30 , 1k1001≤k≤100 ) indicating the number of students and how many throw commands Daenerys calls out, respectively. The following line contains the kk throw commands. Each command is either an integer pp (10000p10000−10000≤p≤10000 ) indicating how many positions to throw the egg clockwise or undo mm (m1m≥1 ) indicating that the last mm throws should be undone. Daenerys never has the kids undo beyond the start of the game.


Output


Display the number of the child with the egg at the end of the game.


Sample Input 1Sample Output 1
5 4
8 -2 3 undo 2
3

Sample Input 2Sample Output 2
5 10
7 -3 undo 1 4 3 -9 5 undo 2 undo 1 6
2
 1 #include <iostream>
 2 #include <sstream>
 3 #include <string>
 4 
 5 using namespace std;
 6 int main()
 7 {
 8 
 9     int n,k,b,o=0;
10     int a[105];
11     string s;
12     cin>>n>>k;
13     for(int i=1;i<=k;i++)
14     {
15         cin>>s;
16         if(s=="undo")
17         {
18             cin>>b;
19             for(int j=o-1;j>=o-b;j--)
20             {
21                 if(a[j]==0) b++;
22                 a[j]=0;
23             }
24                 
25         }
26         else
27         {
28             stringstream sstream;
29             sstream<<s;
30             sstream>>a[o++];
31         }
32     }
33     int sum=0;
34     for(int i=0;i<o;i++)
35     {
36     //    cout<<a[i];
37         sum+=a[i];
38     }
39     int p=(sum%n+n)%n;
40     cout<<p;
41 }

 

posted on 2020-01-22 18:59  CCCherry  阅读(182)  评论(0)    收藏  举报