11398 - The Base-1 Number System

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

Moderator: Board moderators

turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
Location: (CSE,DU) Dhaka,Bangladesh

11398 - The Base-1 Number System

Post by turcse143 »

here is my sample code ples check whats my problem. i got WA.

Code: Select all

#include<stdio.h>
#include<string.h>
#include<math.h>
char str[200],str1[100],del[100];
main()
{

	int i,a,b,c,data[50],j,k,sum;
	freopen("11398.in","rt",stdin);
	while(gets(str))
	{
		if(strcmp(str,"~")==0)
			break;
		strcpy(del," ");
		char *res;
		res=strtok(str,del);
		i=0;sum=0;
		while(res!=NULL)
		{
			strcpy(str1,res);
			if(strcmp(str1,"#")!=0)
			{
				a=strlen(str1);
				if(a==1)
					b=1;
				else if(a==2)
					b=0;
				else
				{
					c=a-2;
					for(j=0;j<c;j++)
					{
						data[i]=b;
						i++;
					}
				}
			}
			res=strtok(NULL,del);
		}
		k=0;
		for(j=i-1;j>=0;j--)
		{
			sum+=(data[j]*(int)pow(2,k));
			k++;
		}
		printf("%d\n",sum);
	}
}
is there any special input output.
''I want to be most laziest person in the world''
CSEDU_1323
New poster
Posts: 10
Joined: Mon Feb 25, 2008 8:22 pm
Location: Dhaka, Bangladesh.

Post by CSEDU_1323 »

sample input

0 0000 00 000 0 0000 #
0 0000
00 000 0 0000 #
~

output
27
27


hope this helps
--- B HAPPY & KEEP SMILING ------
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind »

Did you submit your code with freopen function?
turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
Location: (CSE,DU) Dhaka,Bangladesh

Post by turcse143 »

thank u i got AC now
before that i change my algorithm
there was no problem in freopen.
i took the input in string.
but now take it by %c.
''I want to be most laziest person in the world''
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind »

turcse143 wrote:''I want to be most laziest person in the world''
offtopic: which approach will you follow to achieve that 'glory'?
hunter_du
New poster
Posts: 5
Joined: Fri Feb 22, 2008 10:49 pm

Can anyone tell me why WA??

Post by hunter_du »

Code: Select all

Removed cod, AC NOW
Last edited by hunter_du on Thu Feb 28, 2008 6:06 pm, edited 1 time in total.
turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
Location: (CSE,DU) Dhaka,Bangladesh

Post by turcse143 »

'emotional blind' is a pattern of man.
I have pattern that i want to be a lazy person so that i never
let out from the computer
hope u will understand
''I want to be most laziest person in the world''
turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
Location: (CSE,DU) Dhaka,Bangladesh

Post by turcse143 »

Code: Select all

if(len==1)
            {
               flag=1;
            }
            if(len==2)
            {
               flag=0;
            }
i thing here is ur problem
u set th flag value carefully.
best of luck.
''I want to be most laziest person in the world''
hunter_du
New poster
Posts: 5
Joined: Fri Feb 22, 2008 10:49 pm

Post by hunter_du »

<tar> There is no problem....
Help for the real problem where in my code
Want to learn more.....
shiplu_1320
New poster
Posts: 32
Joined: Sat Dec 29, 2007 9:08 pm
Location: CSEDU , Dhaka
Contact:

Post by shiplu_1320 »

Check your binary to decimal conversion. The bug is in there.
A learner......
hunter_du
New poster
Posts: 5
Joined: Fri Feb 22, 2008 10:49 pm

Post by hunter_du »

Thanks shiplu, There was the bug... Now i got AC...
Want to learn more.....
murad357
New poster
Posts: 2
Joined: Wed Mar 26, 2008 7:33 pm

Re: 11398 - The Base-1 Number System

Post by murad357 »

Is it possible that the input can be like this? :

Code: Select all

0 00 #
0 #
00 #
00 0 #
In my code it is not printing anything for this type of input ( just going to the newline).

If input can be like this, what would be the output? I am not sure why I am getting WA :cry: ?
Thanx in advance.

My Code (in JAVA)

Code: Select all

public class Main 
{	
    public static void main(String[] args) throws IOException 
    {
    	BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    	String totalStr="";
    	String binaryVal="";
    	int flag=-1;
        while (true) 
        {
            String line = reader.readLine();
               
            if (line.equals("~")) 
            {
                break; // end of file reached
            }
            if ( line.charAt(line.length()-1) !='#')
            {
            	totalStr+=line+" ";
            }
            else
            {
            	totalStr+=line;
            	StringTokenizer t = new StringTokenizer(totalStr," #");
            	while(t.hasMoreElements())
            	{
            		String temp=t.nextToken();
            		
            		if(temp.length()==1)
            			flag = 1;
            		else if(temp.length()==2)
            			flag = 0;
            		else
            		{
            			int n= temp.length()-2;
            			
            			for(int i=0;i<n;i++)
            				binaryVal+=flag+"";
            		}	
            	} 
            	if (!binaryVal.equals(""))
            		System.out.println(Integer.parseInt(binaryVal,2));
            	//else
            		//System.out.println(flag);
            	
            	totalStr="";
            	binaryVal="";
            	flag=-1;
            }     
        }// End while         
    }// End main
} //@End Program
Murad
x140l31
Learning poster
Posts: 69
Joined: Tue Jan 30, 2007 12:51 am

Re: 11398 - The Base-1 Number System

Post by x140l31 »

can anyone help me? :-?

I don't know why WA... I tried many cases and it pass all them!

Code: Select all

Removed after AC.

Thanks to lnr
Last edited by x140l31 on Wed Oct 08, 2008 7:43 pm, edited 1 time in total.
lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: 11398 - The Base-1 Number System

Post by lnr »

To x140l31

Try this
Input:

Code: Select all

000 00 0 00 000 #
~
Output:

Code: Select all

0
Last edited by lnr on Fri Oct 17, 2008 9:02 pm, edited 2 times in total.
lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: 11398 - The Base-1 Number System

Post by lnr »

To murad357

For these input:

Code: Select all

0 00 #
0 #
00 #
00 0 #
Output:

Code: Select all

0
0
0
0
Last edited by lnr on Fri Oct 17, 2008 9:01 pm, edited 1 time in total.
Post Reply

Return to “Volume 113 (11300-11399)”