Time Limit: 1s Memory Limit: 32MB
Description
This year, ACM scientific committee members use emails to discuss about the problems and edit the selected ones.
They know that email is not a secure way of communication,
especially on such an important topic.
So they transfer password-protected compressed file among themselves.
In order to send the passwords, they use SMS. To increase the security level, the encrypted passwords are sent by SMS.
To do this, a multi-tap SMS typing method is used.
Multi-tap is currently the most common text input method for mobile phones. With this approach,
the user presses each key one or more times to obtain the wanted characters.
For example, the key 2 is pressed once to get character A, twice for B, and three times for C.
The encryption algorithm that is used is quite simple: to encrypt the ith character of the password,
the key used to obtain that character is tapped i more times. For if the 4th character of password is U,
the key 8 is tapped 6 times, getting the character V.
Note that to make the problem simple, we have assumed that the keypad does not generate digits.
The scientific committee needs a program to decrypt the received passwords.
They are too busy to write this program and have asked you to help!
Write a program to get a correct encrypted text and print the original password.
Input
The input consists of multiple test cases. Each test case contains a non-empty string of length at most 100,
consisting of small or capital English letters. The last line of the input contains a single #.
Output
For each test case, write the decrypted password in a separate line. Note that passwords are case-sensitive.
Sample Input
Copy sample input to clipboard
Sample Output
ABCD
IhateSMS
#include<stdio.h>
int main()
{
char key[8][4]={"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
char in[101],co[101];
int i,j,k=0,l;
while(1)
{
scanf("%s",in);
if(in[0]=='#')
return 0;
for(i=0;in[i]!='/0';i++)
co[i]=in[i];
for(k=0;in[k]!='/0';k++)
for(i=0;i<8;i++)
for(j=0;key[i][j]!='/0'&&j<=3;j++)
{
if(in[k]<'a')
in[k]+=('a'-'A');
if(in[k]==key[i][j])
{ l=j;
if(i<=6&&j-k-1<0&&i!=5)
{while(l-k-1<0)
l+=3;
if(co[k]<'a')
printf("%c",key[i][l-k-1]-('a'-'A'));
else
printf("%c",key[i][l-k-1]);
break;
}
else if((i==7||i==5)&&j-k-1<0)
{
while(l-k-1<0)
l+=4;
if(co[k]<'a')
printf("%c",key[i][l-k-1]-('a'-'A'));
else
printf("%c",key[i][l-k-1]);
}
else
{ if(co[k]<'a')
printf("%c",key[i][l-k-1]-('a'-'A'));
else
printf("%c",key[i][l-k-1]);}
}
}printf("/n");
}
}
1634. Relax! It's just a game
| |
|
Total: | 817 | Accepted: | 328 | Rating: |
2.3/5.0(3 votes)
| |
| |
| | |
| | |
|
Time Limit: 5s Memory Limit: 32MB
Description
You: What's the score? Did I miss much?
Me: It's 2-1 for elAhli and the second half just started. The first half was quite boring.
You: Who scored first? elAhli or ezZamalek?
Me: What difference does it make?
You: Big difference! I can predict the outcome of the match if I knew the order of which goals were
scored in the first half.
Me: What do you mean?
You: It's 2-1 for elAhli, right? One of three things could have happened:
elAhli scored two goals then ezZamalek scored;
Or, elAhli scored its first goal, then ezZamalek, then elAhli again; Or, ezZamalek scored first,
then elAhli scored its two goals.
Me: So?!! I still don't understand what difference does that make? It's still 2-1 for elAhli!
Why don't you just relax and let us continue watching the game in peace.
You: You don't understand!! I believe the probability of who'll win depends on the order of how goals were scored.
Now I have to predict the outcome for 3 possibilities.
Me: And what if the score was 3-2? What would you have done then?
You: I would have to work for 5 different possibilities. No?
Me: Of course not! The number of possibilities isn't always equal to the sum.
You: Can you tell me when will it be equal to the sum?
Me: You're a programmer, why don't you write a program that counts the number of possibilities and compare it to
the sum?
You: I don't have the time, I want to watch the match. Besides, I have nine other problems to worry about.
Me: I'll give you a hint. The possibilities will be equal to the sum only if one of the teams scored a certain number of
goals.
Input
Your program will be tested on one or more test cases. Each test case specifies two natural numbers (A and B )
(separated by one or more spaces) representing the score of the first half.
No team will be able to score more than 10 goals.
The last line of the input file contains two -1's
(which is not part of the test cases.)
Output
Format For each test case where the number of possibilities is equal to the sum, print:
A +B =C
Where A and B are as above and C is their sum. If the number of possibilities is not equal to the sum,
replace the `=' sign with `!=' (without the quotes.)
Sample Input
Copy sample input to clipboard
Sample Output
2+1=3
1+0=1
#include<stdio.h> int mul(int a); int main() { int a,b,sum,scal; while(1) { scanf("%d %d",&a,&b); if(a>10||b>10) return 0; if(a!=-1||b!=-1) {sum=a+b; scal=mul(sum)/mul(b)/mul(a); if(scal==sum) printf("%d+%d=%d/n",a,b,sum); else printf("%d+%d!=%d/n",a,b,sum); } else return 0; }
} int mul(int a) { int i; int sum=1; for(i=1;i<=a;i++) sum*=i; return sum; }
|