10222 - Decode the Mad man

Moderator: Board moderators

amd-RS
New poster
Posts: 27
Joined: Thu Sep 05, 2002 7:37 am

10222 - Decode the Mad man

Hi all,

What should be the answer for the input:

qwaszx

Thanks a lot !!!

Jalal
Learning poster
Posts: 65
Joined: Sun Jun 02, 2002 8:41 pm
Contact:
outputs:
{};`./

amd-RS
New poster
Posts: 27
Joined: Thu Sep 05, 2002 7:37 am
Jalal wrote:outputs:
{};`./
Thanks, I got accepted now

Aur

Isilio
New poster
Posts: 4
Joined: Sun Nov 16, 2003 8:53 am

Problem with scanf...

Hi brothers!!!
How can i know the end of line, in a file that have words separated by a blank space...

Example of a file:

asdasd asdasdasd asdasdasd
asd 3re34 trtet 3ldsd elekwr

deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm
you can use gets to get one line and then tokenize it

ex :
[c]char line[100];
gets (line);

for (int i=0;line!='\0';i++)
if (line==' ') {
//if it's space do something....
}
else {
// do something else....
}
[/c]

another way is to use strtok.

just curious, are you trying to solve 494??

Isilio
New poster
Posts: 4
Joined: Sun Nov 16, 2003 8:53 am

Thanx

I got accepted!!!

no 10222....

snake
New poster
Posts: 4
Joined: Sat Dec 20, 2003 12:05 pm

10222 -WA

Hy! I just can't get rid of that WA. Does anyone know what's wrong with the code?!

Thanks!

[cpp]

#include <iostream>
#include <ctype.h>
using namespace std;

char change(char ch)
{
ch = tolower(ch);
switch(ch)
{
case '}':
return 'p';
case '{':
return 'o';
case 'p':
return 'i';
case 'o':
return 'u';
case 'i':
return 'y';
case 'u':
return 't';
case 'y':
return 'r';
case 't':
return 'e';
case 'r':
return 'w';
case 'e':
return 'q';
case 'w':
return '}';
case 'q':
return '{';
case '`':
return 'l';
case ';':
return 'k';
case 'l':
return 'j';
case 'k':
return 'h';
case 'j':
return 'g';
case 'h':
return 'f';
case 'g':
return 'd';
case 'f':
return 's';
case 'd':
return 'a';
case 's':
return '`';
case 'a':
return ';';
case '/':
return ',';
case '.':
return 'm';
case ',':
return 'n';
case 'm':
return 'b';
case 'n':
return 'v';
case 'b':
return 'c';
case 'v':
return 'x';
case 'c':
return 'z';
case 'x':
return '/';
case 'z':
return '.';
}

}
void main()
{
char line[1000];
int n=0;
char out[1000] ={0};
while(cin.getline(line, 1000))
{
for(int n=0;n<1000;n++)
out[n] = 0;
for(int i=0;i<strlen(line);i++)
{
out = change(line);
}
cout << out << endl;
}

}[/cpp]

osan
New poster
Posts: 47
Joined: Tue Jul 29, 2003 12:03 pm
Contact:

10222

i couldn't get the problem yet.
but do u consider \n??
& check the keyboard that u r not missing any key.
ok?
this time WA
what next...............?

snake
New poster
Posts: 4
Joined: Sat Dec 20, 2003 12:05 pm
What do you mean \n? Is it special in any way?

I think the problem might be that I don't have the US keyboard, and the position of the keys are a bit mixed up.

Am I missing the numbers. I don't know, I can't see that the numbers must also be implemented.

qwaszx outputs {};`./
I found that this is correct (few pages back on this forums).

PS. Do I have to treat shift keys aswell? ([] instead of {} and so)?

keceman
New poster
Posts: 7
Joined: Wed Mar 03, 2004 6:51 am

10222 - invalid memory reference?? what the...

anything wrong with my code?? i got runtime error: invalid memory reference... what's wrong??

/* @JUDGE_ID: 43238WF 10222 C++ */

#include <iostream.h>

int map_row1[12] = {113,119,101,114,116,121,117,105,111,112,91,93};
int map_row2[11] = {97,115,100,102,103,104,106,107,108,59,39};
int map_row3[9] = {122,120,99,118,98,110,109,44,46};

void convertBigChar(char* text)
{
int x=0;
while (text[x] != '\0')
{
if ((text[x] >= 65) && (text[x] <= 90))
{
text[x]=text[x]+32;
}
else if (text[x] == 123) text[x]=91;
else if (text[x] == 125) text[x]=93;
else if (text[x] == 34) text[x]=39;
else if (text[x] == 58) text[x]=59;
else if (text[x] == 62) text[x]=44;
else if (text[x] == 60) text[x]=46;
x++;
}
}

void process(char* text)
{
int x=0,y;
while (text[x] != '\0')
{
for (y=0;y<12;y++) // map_row 1
{
if (text[x] == map_row1[y])
{
text[x]=map_row1[y-2];
break;
}
}
for (y=0;y<11;y++) // map_row 2
{
if (text[x] == map_row2[y])
{
text[x]=map_row2[y-2];
break;
}
}
for (y=0;y<9;y++) // map_row 3
{
if (text[x] == map_row3[y])
{
text[x]=map_row3[y-2];
break;
}
}
x++;
}
}

void main()
{
char a;
char *text;
int x, length;
while ((cin != 0))
{
text = new char [32];
x = 0;
a = cin.get();
while (a != '\n')
{
text[x]=a;
x++;
a=cin.get();
}
length=x;
text[x]='\0';
convertBigChar(text);
process(text);
cout << text << endl;
delete [] text;
}
}

alu_mathics
Learning poster
Posts: 55
Joined: Sat Jan 24, 2004 9:30 pm
Location: Chittagong
Contact:
i made the followung changes.Its ok now.If u got ac inform me.
#include <iostream.h>
#include <stdio.h>

int map_row1[12] = {113,119,101,114,116,121,117,105,111,112,91,93};
int map_row2[11] = {97,115,100,102,103,104,106,107,108,59,39};
int map_row3[9] = {122,120,99,118,98,110,109,44,46};

void convertBigChar(char* text)
{
int x=0;
while (text[x] != '\0')
{
if ((text[x] >= 65) && (text[x] <= 90))
{
text[x]=text[x]+32;
}
else if (text[x] == 123) text[x]=91;
else if (text[x] == 125) text[x]=93;
else if (text[x] == 34) text[x]=39;
else if (text[x] == 5) text[x]=59;
else if (text[x] == 62) text[x]=44;
else if (text[x] == 60) text[x]=46;
x++;
}
}

void process(char* text)
{
int x=0,y;
while (text[x] != '\0')
{
for (y=0;y<12;y++) // map_row 1
{
if (text[x] == map_row1[y])
{
text[x]=map_row1[y-2];
break;
}
}
for (y=0;y<11;y++) // map_row 2
{
if (text[x] == map_row2[y])
{
text[x]=map_row2[y-2];
break;
}
}
for (y=0;y<9;y++) // map_row 3
{
if (text[x] == map_row3[y])
{
text[x]=map_row3[y-2];
break;
}
}
x++;
}
}

void main()
{
char a;
char *text;
int x, length;
while (1)//(cin != 0))
{
text = new char [100000];
x = 0;
a = cin.get();
if(feof(stdin))break;
while (a != '\n')
{
text[x]=a;
x++;
a=cin.get();
}
length=x;
text[x]='\0';
convertBigChar(text);
process(text);
cout << text << endl;
//delete [] text;
}
}
cuii e

_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Greetings!.
For this problem I considered only these characters, and the "space bar", as valid input:

Code: Select all

``ertyuiop[]dfghjkl;'cvbnm,.``
Hope it helps.
_.

midra
Experienced poster
Posts: 119
Joined: Fri Feb 13, 2004 7:20 am
Contact:

10222 WA ..WHY!!

Maybe because I have an spanish keyboard, but I think I make a correct intialization of the keys.
I get WA over and over again.
here is my code:

[c]
#include <stdio.h>

int main()
{
char a[100000];
char C[47]={"{}qwertyuiop[];

efr_shovo
New poster
Posts: 38
Joined: Wed Sep 22, 2004 9:09 am

10222 Why P.E

/* Why This Gives P.E Pleaze Help

#include<stdio.h>
#define MAX 300
char kb[MAX];
char str[10000];
int i;
void main()
{
kb['e']='q';
kb['r']='w';
kb['t']='e';
kb['y']='r';

kb['u']='t';
kb['i']='y';
kb['o']='u';
kb['p']='i';
kb['[']='o';

kb[']']='p';
kb['\\']='[';

kb['2']='`';
kb['3']='1';
kb['4']='2';
kb['5']='3';

kb['6']='4';
kb['7']='5';
kb['8']='6';
kb['9']='7';
kb['0']='8';

kb['-']='9';
kb['=']='0';
kb['=']='0';

kb['d']='a';
kb['f']='s';
kb['g']='d';
kb['h']='f';

kb['j']='g';
kb['k']='h';
kb['l']='j';
kb[';']='k';
kb['\'']='l';

kb['\\']=';';

kb['c']='z';
kb['v']='x';
kb['b']='c';
kb['n']='v';

kb['m']='b';
kb[',']='n';
kb['.']='m';
kb['/']=',';
while(gets(str))
{
while(str)
{
if(kb[str]=='\0')
putchar(str[i++]);
else
putchar(kb[str[i++]]);
}
i=0;
}
}

Qbens
New poster
Posts: 5
Joined: Fri Apr 23, 2004 11:37 pm
Location: Poland
Contact:
1. Change this:

Code: Select all

``````case '}':
return 'p';
case '{':
return 'o';
``````
for this:

Code: Select all

``````case ']':
return 'p';
case '[':
return 'o';
``````
``````case ' ':