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

x140l31
Learning poster
Posts: 69
Joined: Tue Jan 30, 2007 12:51 am

Re: 11398 - The Base-1 Number System

Post by x140l31 » Tue Oct 07, 2008 10:16 pm

lnr wrote:To x140l31

Try this
Input:

Code: Select all

000 00 0 00 000 #
~
Output:

Code: Select all

2
Thanks all.
:-? why!!!

000 is ignored (it's a valid input? doesn't matter...) RESULT = 0
00 FLAG = 0 RESULT = 0
0 FLAG = 1 RESULT = 0
00 FLAG = 0 RESULT = 0
000 push 3-2=1 digits of FLAG = 0 RESULT = 0

result = 0

lnr
Experienced poster
Posts: 141
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: 11398 - The Base-1 Number System

Post by lnr » Wed Oct 08, 2008 6:35 am

I am very sorry.

Input:

Code: Select all

000 00 0 00 000 #
~
Output:

Code: Select all

0
I updated the output.
Last edited by lnr on Fri Oct 17, 2008 8:53 pm, edited 1 time in total.

lnr
Experienced poster
Posts: 141
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: 11398 - The Base-1 Number System

Post by lnr » Wed Oct 08, 2008 7:17 am

To x140l31

Submit your code again.
I did not know that GNU C++ compiler supports and operator.

Code: Select all

while (cin >> block and block != "~")
is similar to

Code: Select all

while (cin >> block && block != "~")
Returning a value from int main() is a good practice.
You will get accepted.
May be you submitted wrong code before.
And don't forget to remove your code.
Last edited by lnr on Fri Oct 17, 2008 8:54 pm, edited 1 time in total.

x140l31
Learning poster
Posts: 69
Joined: Tue Jan 30, 2007 12:51 am

Re: 11398 - The Base-1 Number System

Post by x140l31 » Wed Oct 08, 2008 7:50 pm

lnr wrote:To x140l31

Submit your code again.
I did not know that GNU C++ compiler supports and operator.

Code: Select all

while (cin >> block and block != "~")
is similar to

Code: Select all

while (cin >> block && block != "~")
Returning a value from int main() is a good practice.
You will get accepted.
May be you submitted wrong code before.
And don't forget to remove your code.

Thanks all.
I changed "and" to "&&" and i got AC...

why?

I always used "and" in al my programs, and never I got any problem :?

nayimsust
New poster
Posts: 9
Joined: Wed Aug 27, 2008 6:50 pm

Re: 11398 - The Base-1 Number System

Post by nayimsust » Wed Jan 28, 2009 4:35 pm

you must get inputs by using either scanf("%s") or scanf("%c")
because input may be given in the following format

input:
0000 0 0000 00
000 0 0000 #

output:
27

may it helps you
:D

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 11398 - The Base-1 Number System

Post by sazzadcsedu » Mon Jun 22, 2009 10:50 pm

nayimsust wrote-
you must get inputs by using either scanf("%s") or scanf("%c")
because input may be given in the following format
thats not true.you can use gets to take input.because each block is seperated by a space.
so the judge input is

Code: Select all

look like
0000 0 0000 00(space here)
000 0 0000 #
not like
0000 0 0000 00(without space)
000 0 0000 #
and first block may contain more than two 0.so your code need to ignore it.and when there is a consequetive block of one and two zero,and then larger block,u should consider the last (one/two) no. zero block for the larger block.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

buppy
New poster
Posts: 2
Joined: Tue Nov 08, 2011 11:26 pm

Re: 11398 - The Base-1 Number System

Post by buppy » Tue Nov 08, 2011 11:35 pm

can any one help why i am getting wa,

Code: Select all

#include<stdio.h>
#include<math.h>
int main()
{
char ch,f,ch1[100];
int i,j,len,sp,c,d,o=0;
double sum,sum1,k;
len=0;
sp=0;
j=0;
while(scanf("%c",&ch)==1){
if(ch=='0')
len++;
else if(ch==' ') {
sp++;
if(sp==1&&len>2)
o=1;
else if((len==1||len==2)&&sp%2!=0)
	{
c=len;
if(c==1)
f='1';
else
f='0';
	}
	else{
	d=len-2;
	for(i=0;i<d;i++)
	ch1[i+j]=f;

	j=i+j;
	}
len=0;

		}
else if(ch=='#'){
  if(o==1)
  sum1=0;
  else{
k=0;
for(i=j-1;i>=0;i--){
sum=ch1[i]-48;
sum=sum*pow(2,k);
sum1=sum1+sum;
k++;
}
		}
printf("%0.f\n",sum1);
sum1=0;
len=0;
sp=0;
j=0;
o=0;
}
else if(ch=='~')
break;
}

return 0;
}

Nafis0001
New poster
Posts: 6
Joined: Fri Mar 23, 2012 10:02 pm

Re: 11398 - The Base-1 Number System

Post by Nafis0001 » Wed Jul 18, 2012 10:27 am

please someone help me....getting wrong answer

Code: Select all

#include<cstdio>
#include<vector>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{char a[1000];int i,j,l,x;
 vector<int>v;
while(scanf("%s",a))
{if(a[0]=='~')
 break; v.clear();x=0;
while(a[0]!='#')
{l=strlen(a);
 if(l==1)
 x=1;
 if(l==2)
 x=0;
 else
 {for(i=2;i<l;i++)
  v.push_back(x);}
 scanf("%s",a);}
int y=v.size();
double s,k;s=0;
for(i=y-1;i>=0;i--)
{k=pow(2,i);
 s+=v[i]*k;}
printf("%.0lf\n",s);}
return 0;}


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

Re: 11398 - The Base-1 Number System

Post by brianfry713 » Thu Jul 19, 2012 3:36 am

Don't use doubles.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 113 (11300-11399)”