## 10878 - Decode the tape

Moderator: Board moderators

### 10878 - Decode the tape

Can someone reply me how's the "morse code" would be? Here's my discovery for that problem, is it right or is there something missing?

Code: Select all
`a  00**.**0    A  0***.**0b  00**.*0*    B  0***.*0*c  00**.*00    C  0***.*00d  00**.0**    D  0***.0**e  00**.0*0    E  0***.0*0f  00**.00*    F  0***.00*g  00**.000    G  0***.000h  00*0.***    H  0**0.***i  00*0.**0    I  0**0.**0j  00*0.*0*    J  0**0.*0*k  00*0.*00    K  0**0.*00l  00*0.0**    L  0**0.0**m  00*0.0*0    M  0**0.0*0n  00*0.00*    N  0**0.00*o  00*0.000    O  0**0.000p  000*.***    P  0*0*.***q  000*.**0    Q  0*0*.**0r  000*.*0*    R  0*0*.*0*s  000*.*00    S  0*0*.*00t  000*.0**    T  0*0*.0**u  000*.0*0    U  0*0*.0*0v  000*.00*    V  0*0*.00*w  000*.000    W  0*0*.000x  0000.***    X  0*00.***y  0000.**0    Y  0*00.**0z  0000.*0*    Z  0000.*0*_  *0**.***.  *0*0.00*\n ***0.*0*`

Roby
Experienced poster

Posts: 101
Joined: Wed May 04, 2005 4:33 pm
Location: Tangerang, Banten, Indonesia

The code are just normal ASCII values. On the first sight, your value for capital Z is wrong.

misof
A great helper

Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm

how to know and convert the ASCII value to tape's "morse" code? I really don't understand. Those are my guessing only especially for the quotation and upper case letters.

Roby
Experienced poster

Posts: 101
Joined: Wed May 04, 2005 4:33 pm
Location: Tangerang, Banten, Indonesia

There is nothing related to morse code.
Ignore the columns of '|' and '.' There is eight characters in each row. They form a 8-bit code. 'o' is 1 and space is 0. So the first row of the sample means 01000001 which is 65 and it is the ascii value of 'A'.

Cho
A great helper

Posts: 274
Joined: Wed Oct 20, 2004 11:51 pm
Location: Hong Kong

Cho wrote:There is nothing related to morse code.
Ignore the columns of '|' and '.' There is eight characters in each row. They form a 8-bit code. 'o' is 1 and space is 0. So the first row of the sample means 01000001 which is 65 and it is the ascii value of 'A'.

Thanks to Cho. Without any explanation of the code in the problem, it was almost meaningless!
mamun
A great helper

Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm

Hey Guys,

I'm so stumped. I bet you the reason my program is getting WA is because I'm using something that isn't available in the judge's version of the compiler.

I ran this, and it works fine. I even modified my codes to ignore '|' and '.', just in case they stuck them in there. Can anyone see what's wrong with my codes?:

Code: Select all
`#include <iostream>#include <string>using namespace std;int binToI(string s){  int i;  int value = 0;  int n = 128;  for (i=0; i<s.length(); i++)    {      while (s[i] == '|' || s[i] == '.')        i++;      if (s[i] == 'o'){        value = value + n;      }      n=n/2;    }  return value;}int main(){  int i;  char c;  int val;  string s;  getline(cin, s);  while (!cin.eof()){    val = binToI(s);    c = (char)val;    cout<<c;    getline(cin, s);  }  return 0;}`

Thanks
jjtse
Learning poster

Posts: 80
Joined: Mon Aug 22, 2005 7:32 pm

jjtse wrote:Hey Guys,

I'm so stumped. I bet you the reason my program is getting WA is because I'm using something that isn't available in the judge's version of the compiler.

I ran this, and it works fine. I even modified my codes to ignore '|' and '.', just in case they stuck them in there. Can anyone see what's wrong with my codes?:

The input begins with line "___________" that your method decodes to 0. You shouldn't write this 0 to the output.

Martin Macko
A great helper

Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Code: Select all
`code removed after AC `

plz give the test cases for which it is incorret or point out mistakes...
plz help me out...
Last edited by vinit_iiita on Thu Aug 24, 2006 10:16 am, edited 1 time in total.
win
vinit_iiita
New poster

Posts: 30
Joined: Mon Jun 19, 2006 10:37 pm

vinit_iiita wrote:plz give the test cases for which it is incorret or point out mistakes...
plz help me out...

You output garbage (namely ASCII 0x00) after the last character.

Martin Macko
A great helper

Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

hi plz tell me how can i avoid that. i could not figure out how...
win
vinit_iiita
New poster

Posts: 30
Joined: Mon Jun 19, 2006 10:37 pm

i would like to know its elobaration...
win
vinit_iiita
New poster

Posts: 30
Joined: Mon Jun 19, 2006 10:37 pm

vinit_iiita wrote:hi plz tell me how can i avoid that. i could not figure out how...

You are getting the ASCII symbol 0x00 from the last input line '___________'. Make sure, your program doesn't try to translate this line.

Martin Macko
A great helper

Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

thanks a lot martin...i got ac now...
win
vinit_iiita
New poster

Posts: 30
Joined: Mon Jun 19, 2006 10:37 pm

### 10878 pls help

pls help me. i dont know y im getting WA. this is my code:

#include<iostream.h>
#include<stdio.h>
#include<string.h>

int main()
{
char start[20],end[20], middle[1000][20];
int i,j,k,l;

while(gets(start))
{

i=0;

while(gets(middle[i++]))
{
if(!strcmp("| o. o |",middle[i-1])) break;
}

gets(end);

for(j=0;j<i;j++)
{

if(!strcmp(middle[j],"| oo . o|")) cout<<"a";
else if(!strcmp(middle[j],"| o . o|")) cout<<"A";
else if(!strcmp(middle[j],"| o . |")) cout<<" ";

else if(!strcmp(middle[j],"| ooo . o|")) cout<<"q";
else if(!strcmp(middle[j],"| o o . o|")) cout<<"Q";
else if(!strcmp(middle[j],"| ooo .o o|")) cout<<"u";
else if(!strcmp(middle[j],"| o o .o o|")) cout<<"U";
else if(!strcmp(middle[j],"| oo o. o|")) cout<<"i";
else if(!strcmp(middle[j],"| o o. o|")) cout<<"I";
else if(!strcmp(middle[j],"| oo . oo|")) cout<<"c";
else if(!strcmp(middle[j],"| o . oo|")) cout<<"C";
else if(!strcmp(middle[j],"| oo o. oo|")) cout<<"k";
else if(!strcmp(middle[j],"| o o. oo|")) cout<<"K";

else if(!strcmp(middle[j],"| oo . o |")) cout<<"b";
else if(!strcmp(middle[j],"| o . o |")) cout<<"B";
else if(!strcmp(middle[j],"| ooo . o |")) cout<<"r";
else if(!strcmp(middle[j],"| o o . o |")) cout<<"R";
else if(!strcmp(middle[j],"| oo o.ooo|")) cout<<"o";
else if(!strcmp(middle[j],"| o o.ooo|")) cout<<"O";
else if(!strcmp(middle[j],"| ooo .ooo|")) cout<<"w";
else if(!strcmp(middle[j],"| o o .ooo|")) cout<<"W";
else if(!strcmp(middle[j],"| oo o.oo |")) cout<<"n";
else if(!strcmp(middle[j],"| o o.oo |")) cout<<"N";

else if(!strcmp(middle[j],"| oo .oo |")) cout<<"f";
else if(!strcmp(middle[j],"| o .oo |")) cout<<"F";
else if(!strcmp(middle[j],"| oooo. |")) cout<<"x";
else if(!strcmp(middle[j],"| o oo. |")) cout<<"X";

else if(!strcmp(middle[j],"| oo o. o |")) cout<<"j";
else if(!strcmp(middle[j],"| o o. o |")) cout<<"J";
else if(!strcmp(middle[j],"| ooo .o o|")) cout<<"u";
else if(!strcmp(middle[j],"| o o .o o|")) cout<<"U";
else if(!strcmp(middle[j],"| oo o.o o|")) cout<<"m";
else if(!strcmp(middle[j],"| o o.o o|")) cout<<"M";
else if(!strcmp(middle[j],"| ooo . |")) cout<<"p";
else if(!strcmp(middle[j],"| o o . |")) cout<<"P";
else if(!strcmp(middle[j],"| ooo . oo|")) cout<<"s";
else if(!strcmp(middle[j],"| o o . oo|")) cout<<"S";

else if(!strcmp(middle[j],"| ooo .oo |")) cout<<"v";
else if(!strcmp(middle[j],"| o o .oo |")) cout<<"V";
else if(!strcmp(middle[j],"| oo .o o|")) cout<<"e";
else if(!strcmp(middle[j],"| o .o o|")) cout<<"E";
else if(!strcmp(middle[j],"| ooo . o |")) cout<<"r";
else if(!strcmp(middle[j],"| o o . o |")) cout<<"R";

else if(!strcmp(middle[j],"| ooo .o |")) cout<<"t";
else if(!strcmp(middle[j],"| o o .o |")) cout<<"T";
else if(!strcmp(middle[j],"| oo o. |")) cout<<"h";
else if(!strcmp(middle[j],"| o o. |")) cout<<"H";

else if(!strcmp(middle[j],"| oo o.o |")) cout<<"l";
else if(!strcmp(middle[j],"| o o.o |")) cout<<"L";
else if(!strcmp(middle[j],"| oooo. o |")) cout<<"z";
else if(!strcmp(middle[j],"| o oo. o |")) cout<<"Z";
else if(!strcmp(middle[j],"| oooo. o|")) cout<<"y";
else if(!strcmp(middle[j],"| o oo. o|")) cout<<"Y";

else if(!strcmp(middle[j],"| oo .o |")) cout<<"d";
else if(!strcmp(middle[j],"| o .o |")) cout<<"D";
else if(!strcmp(middle[j],"| oo .ooo|")) cout<<"g";
else if(!strcmp(middle[j],"| o .ooo|")) cout<<"G";
else if(!strcmp(middle[j],"| o o.oo |")) cout<<".";
else if(!strcmp(middle[j],"| o.oo |")) cout<<",";
else if(!strcmp(middle[j],"| o. o |")) cout<<"\n";

}

}

return 0;
}
rafi6047
New poster

Posts: 3
Joined: Tue Oct 10, 2006 5:02 pm

Search about ascii, and you well get it.

rio
A great helper

Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Next