Page 1 of 2

11398 - The Base-1 Number System

Posted: Mon Feb 25, 2008 11:59 am
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.

Posted: Mon Feb 25, 2008 8:26 pm
by CSEDU_1323
sample input

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

output
27
27


hope this helps

Posted: Tue Feb 26, 2008 2:33 am
by emotional blind
Did you submit your code with freopen function?

Posted: Tue Feb 26, 2008 12:16 pm
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.

Posted: Tue Feb 26, 2008 6:04 pm
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'?

Can anyone tell me why WA??

Posted: Wed Feb 27, 2008 4:18 pm
by hunter_du

Code: Select all

Removed cod, AC NOW

Posted: Wed Feb 27, 2008 4:21 pm
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

Posted: Wed Feb 27, 2008 4:28 pm
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.

Posted: Wed Feb 27, 2008 10:24 pm
by hunter_du
<tar> There is no problem....
Help for the real problem where in my code

Posted: Thu Feb 28, 2008 7:28 am
by shiplu_1320
Check your binary to decimal conversion. The bug is in there.

Posted: Thu Feb 28, 2008 6:04 pm
by hunter_du
Thanks shiplu, There was the bug... Now i got AC...

Re: 11398 - The Base-1 Number System

Posted: Fri Apr 11, 2008 4:48 pm
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

Re: 11398 - The Base-1 Number System

Posted: Fri Aug 15, 2008 3:31 pm
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

Re: 11398 - The Base-1 Number System

Posted: Tue Oct 07, 2008 4:29 pm
by lnr
To x140l31

Try this
Input:

Code: Select all

000 00 0 00 000 #
~
Output:

Code: Select all

0

Re: 11398 - The Base-1 Number System

Posted: Tue Oct 07, 2008 4:37 pm
by lnr
To murad357

For these input:

Code: Select all

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

Code: Select all

0
0
0
0