10878 - Decode the tape

All about problems in Volume 108. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

User avatar
rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Post by rio » Thu Oct 12, 2006 9:06 am

Search about ascii, and you well get it.

maxbcr2000
New poster
Posts: 3
Joined: Tue Oct 03, 2006 4:59 pm

Post by maxbcr2000 » Fri Oct 13, 2006 12:17 pm

I got a WA!

#include <cstdlib>
#include <iostream>
#include <math.h>
#include <cstring>

using namespace std;

int main(int argc, char *argv[])
{
int check=0,x=0;
char n[12],nn[999];
while(cin.getline(n,12)) //n[6]='.',n[0],n[10]='|'
{
int sum=0;
if (n[0]=='_' && check==1) break;
if (n[0]=='_' && check==0) check++;
if (n[0]!='_')
{for (int i=1;i<strlen(n)-1;i++)
{
if (i<6 && n=='o') sum+=pow(2,8-i);
if (i>6 && n=='o') sum+=pow(2,9-i);
}
nn[x]=char(sum);
x++;
}

}
for (int j=0;j<x-1;j++) cout<<nn[j];
system("PAUSE");
return EXIT_SUCCESS;

}

WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

10878 decode the tape

Post by WR » Sat Nov 25, 2006 12:47 pm

anybody cares to verify the following input/output?

Code: Select all

___________
|  o  . o |
|  oo .   |
|  oo .  o|
|  oo . o |
|  oo . oo|
|  oo .o  |
|  oo .o o|
|  oo .oo |
|  oo .ooo|
|  ooo.   |
|  ooo.  o|
| o   .  o|
| o   . o |
| o   . oo|
| o   .o  |
| o   .o o|
| o   .oo |
| o   .ooo|
| o  o.   |
| o  o.  o|
| o  o. o |
| o  o. oo|
| o  o.o  |
| o  o.o o|
| o  o.oo |
| o  o.ooo|
| o o .   |
| o o .  o|
| o o . o |
| o o . oo|
| o o .o  |
| o o .o o|
| o o .oo |
| o o .ooo|
| o oo.   |
| o oo.  o|
| o oo. o |
| oo  .  o|
| oo  . o |
| oo  . oo|
| oo  .o  |
| oo  .o o|
| oo  .oo |
| oo  .ooo|
| oo o.   |
| oo o.  o|
| oo o. o |
| oo o. oo|
| oo o.o  |
| oo o.o o|
| oo o.oo |
| oo o.ooo|
| ooo .   |
| ooo .  o|
| ooo . o |
| ooo . oo|
| ooo .o  |
| ooo .o o|
| ooo .oo |
| ooo .ooo|
| oooo.   |
| oooo.  o|
| oooo. o |
|  o  . o |
|    o. o |
|    o.o o|
| o oo.o  |
|  ooo. o |
|  ooo. oo|
|  ooo.o  |
|  ooo.o o|
|  ooo.oo |
|  ooo.ooo|
| o   .   |
|  o  .   |
| o oo. oo|
| o oo.o  |
| o oo.o o|
| o oo.oo |
| o oo.ooo|
| oo  .   |
| o oo.o  |
|    o. o |
|    o.o o|
|  o  .  o|
|  o  . o |
|  o  . oo|
|  o  .o  |
|  o  .o o|
|  o  .oo |
|  o  .ooo|
|  o o.   |
|  o o.  o|
|  o o. o |
|  o o. oo|
|  o o.o  |
|  o o.o o|
|  o o.oo |
|  o o.ooo|
| oooo. oo|
| oooo.o  |
| oooo.o o|
| oooo.oo |
|    o. o |
|    o.o o|
| o   .  o|
| o   . o |
| o   . oo|
| o   .o  |
| o   .o o|
| o   .oo |
| o   .ooo|
| o  o.   |
| o  o.  o|
| o  o. o |
| o  o. oo|
| o  o.o  |
| o  o.o o|
| o  o.oo |
| o  o.ooo|
| o o .   |
| o o .  o|
| o o . o |
| o o . oo|
| o o .o  |
| o o .o o|
| o o .oo |
| o o .ooo|
| o oo.   |
| o oo.  o|
| o oo. o |
|    o. o |
| oo  .  o|
| oo  . o |
| oo  . oo|
| oo  .o  |
| oo  .o o|
| oo  .oo |
| oo  .ooo|
| oo o.   |
| oo o.  o|
| oo o. o |
| oo o. oo|
| oo o.o  |
| oo o.o o|
| oo o.oo |
| oo o.ooo|
| ooo .   |
| ooo .  o|
| ooo . o |
| ooo . oo|
| ooo .o  |
| ooo .o o|
| ooo .oo |
| ooo .ooo|
| oooo.   |
| oooo.  o|
| oooo. o |
|    o. o |
|    o.o o|
| o   .  o|
| o   . o |
| o   . oo|
| o   .o  |
| o   .o o|
| o   .oo |
| o   .ooo|
| o  o.   |
| o  o.  o|
| o  o. o |
| o  o. oo|
| o  o.o  |
| o  o.o o|
| o  o.oo |
| o  o.ooo|
| o o .   |
| o o .  o|
| o o . o |
| o o . oo|
| o o .o  |
| o o .o o|
| o o .oo |
| o o .ooo|
| o oo.   |
| o oo.  o|
| o oo. o |
|    o.o o|
|  oo .   |
|  oo .  o|
|  oo . o |
|  oo . oo|
|  oo .o  |
|  oo .o o|
|  oo .oo |
|  oo .ooo|
|  ooo.   |
|  ooo.  o|
|    o. o |
|    o.o o|
|  o  . o |
|  o  .ooo|
|  oo .   |
|  oo .  o|
|  oo . o |
|  oo . oo|
|  oo .o  |
|  oo .o o|
|  oo .oo |
|  oo .ooo|
|  ooo.   |
|  ooo.  o|
|    o.  o|
|  oo .   |
|  oo .  o|
|  oo . o |
|  oo . oo|
|  oo .o  |
|  oo .o o|
|  oo .oo |
|  oo .ooo|
|  ooo.   |
|  ooo.  o|
|    o.   |
|  oo .   |
|  oo .  o|
|  oo . o |
|  oo . oo|
|  oo .o  |
|  oo .o o|
|  oo .oo |
|  oo .ooo|
|  ooo.   |
|  ooo.  o|
|  o  .ooo|
|  o  . o |
|    o. o |
| o   .  o|
|  o  .   |
| ooo .  o|
| ooo .o o|
| oo o.  o|
| oo  . oo|
| oo o. oo|
|  o  .   |
| oo  . o |
| ooo . o |
| oo o.ooo|
| ooo .ooo|
| oo o.oo |
|  o  .   |
| oo  .oo |
| oo o.ooo|
| oooo.   |
|  o  .   |
| oo o. o |
| ooo .o o|
| oo o.o o|
| ooo .   |
| ooo . oo|
|  o  .   |
| oo o.ooo|
| ooo .oo |
| oo  .o o|
| ooo . o |
|  o  .   |
| ooo .o  |
| oo o.   |
| oo  .o o|
|  o  .   |
| oo o.o  |
| oo  .  o|
| oooo. o |
| oooo.  o|
|  o  .   |
| oo  .o  |
| oo o.ooo|
| oo  .ooo|
|  o o.oo |
|    o. o |
___________

Code: Select all

"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

\:;<=>?@ [\]^_'\

!"#$%&'()*+,-./{|}~

ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz

ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789

"'0123456789    01234567890123456789'"
A quick brown fox jumps over the lazy dog.
In the last line but one are a TAB and a BACKSPACE character.

apurba
New poster
Posts: 42
Joined: Sun Oct 07, 2007 10:29 pm

Re: 10878 - Decode the tape

Post by apurba » Wed May 07, 2008 8:44 am

any one pls help me to find the bug.........
i m really confused.............
here is my code...........

Code: Select all

/*****  decode the tape @ 10878  *****/

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

[b][size=150]accepted[/size][/b]


		
thanks in advance.........
Last edited by apurba on Thu Jun 12, 2008 9:55 am, edited 2 times in total.

Code: Select all

keep dreaming...

snail.123
New poster
Posts: 14
Joined: Wed Jun 13, 2007 3:29 am
Location: Taiwan

Re: 10878 - Decode the tape

Post by snail.123 » Wed May 07, 2008 1:53 pm

For the first and last line of "___________", you should not output anything. But your code ouputs '\0' for those lines of input.

ali1024
New poster
Posts: 1
Joined: Sun Oct 30, 2011 7:42 pm

Re: 10878 - Decode the tape

Post by ali1024 » Sun Oct 30, 2011 7:53 pm

pls help me !
why go to WA
i m check all state true but go to Wa

Code: Select all

#include <stdio.h>
int pow2(int t){
	int p=1;
	while(t-->0)
		p*=2;
	return p;
}
char decode(char *str){
	char ch,i;
	for(i=9;i>6;i--)
		if(*(str+i)=='o')
			ch+=pow2(9-i);
    for(i=5;i>1;i--)
		if(*(str+i)=='o')
			ch+=pow2(8-i);
	return ch;
}
int main()
{
    char str[12];
    while(gets(str)){
    	if(str[0]=='_')
    		continue;
    	printf("%c",decode(str));
    }
    return 0;
}


dibery
Learning poster
Posts: 76
Joined: Sat Feb 23, 2013 4:16 pm
Location: Taiwan, Taipei
Contact:

Re: 10878 - Decode the tape

Post by dibery » Sun Jul 28, 2013 8:08 am

Hi, I'm having some problems on this problem.

My method calculates the ascii code value of each line and then output this char, but I'm unable to find the mistakes...

Code: Select all

Got AC. Thanks brianfry.
Deciding whether to print a new line at the end is so difficult...
Last edited by dibery on Mon Jul 29, 2013 12:16 pm, edited 2 times in total.
Life shouldn't be null.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10878 - Decode the tape

Post by brianfry713 » Mon Jul 29, 2013 5:18 am

Don't print a blank line at the end.
Check input and AC output for thousands of problems on uDebug!

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10878 - Decode the tape

Post by uDebug » Fri Feb 21, 2014 1:21 pm

WR wrote:anybody cares to verify the following input/output?
7+ years down the line, and I do. Thanks for sharing. This was really useful during testing / debugging. My AC program gives the same output as yours does.

For anyone wondering about newlines, as brianfry713 and dibery have shared with us, do not print any on your own. If you look at the sample input carefully (after you've figured out what the code is), observe that

Code: Select all

|    o. o |
is actually a newline character.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Post Reply

Return to “Volume 108 (10800-10899)”