All about problems in Volume 110. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
kolpobilashi
Learning poster
Posts: 54 Joined: Mon Jan 02, 2006 3:06 am
Location: Dhaka,Bangladesh
Contact:
Post
by kolpobilashi » Fri Sep 15, 2006 6:27 am
Why WA?? would anyone explain me plz.....thanx in advance.
Code: Select all
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define MAX 50
typedef long long ul;
double test(char *str)
{
int de[MAX]={0};
int ss[300] = {0};
int pp= strlen(str);
int i,j=0;
double c=1,d=1;
for(i=0;i<pp;i++)
{
ss[str[i]]++;
if(ss[str[i]] > 1)
de[j++] = ss[str[i]];
}
c = 1;
for(i=2;i<=pp;i++)
{
c*=i;
if(j>0)
d*= de[--j];
if((d!=1) && !(fmod(c,d)))
{
c /= d;
d=1;
}
}
return c;
}
int main()
{
int n;
while(scanf("%d",&n)==1&&n)
{
char str[MAX];
int p,temp;
for(p=0;p<n;p++)
{
scanf("%d",&temp);
str[p]=temp+'0';
}
str[p]='\0';
double perm;
perm=test(str);
ul perm1=(ul)perm;
perm1=perm1/n;
ul i,sum=0,ans=0;
for(i=0;i<n;i++)
{
sum+=(str[i]-'0')*perm1;
}
//printf("%lld\n",sum);
for( i=0;i<n;i++)
{
ans*=10;
ans+=sum;
}
printf("%lld\n",ans);
str[0]='\0';
}
return 0;
}
Sanjana
mamun
A great helper
Posts: 286 Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:
Post
by mamun » Fri Sep 15, 2006 2:19 pm
You might like to try the inputs given in earlier posts.
ayon
Experienced poster
Posts: 161 Joined: Tue Oct 25, 2005 8:38 pm
Location: buet, dhaka, bangladesh
Post
by ayon » Fri Sep 15, 2006 2:53 pm
avoid floating point number where possible, if you are bound to use floating point number, do not write code like d != 1, as 5.00/5.00 may return 0.99999999 or 1.0000000001 or something like this.
ishtiak zaman
----------------
the world is nothing but a good program, and we are all some instances of the program
Rainy Day
New poster
Posts: 8 Joined: Sun Sep 10, 2006 9:03 am
Post
by Rainy Day » Fri Sep 15, 2006 3:10 pm
Why WA??
'cause it's wrong.
try this simple input:
5
1 1 1 1 1
output:
11111
but ur out put:
0
which is simply wrong .
jbh
New poster
Posts: 4 Joined: Fri Aug 04, 2006 7:33 pm
Post
by jbh » Sat Sep 16, 2006 9:50 am
anyone can give me some sample i/o? my code passed all those given here..but still WA!!
what is the output for these input:
Code: Select all
12
9 0 0 0 0 0 0 0 0 0 0 9
12
0 0 0 0 0 0 0 0 0 0 0 9
11
9 8 7 6 5 4 3 2 1 0 0
12
9 8 7 6 5 4 3 2 1 1 1 1
12
0 1 2 3 0 1 0 7 0 9 6 0
12
9 0 0 0 0 9 0 0 0 0 0 9
3
0 3 3
3
0 0 3
3
0 2 3
3
3 3 3
7
1 2 3 4 5 6 7
7
9 8 7 6 5 4 3
5
5 5 3 6 8
5
1 3 5 7 9
6
1 3 5 7 9 0
5
2 4 6 8 0
4
8 9 8 9
4
7 5 7 3
0
my output:
Code: Select all
10999999999989
999999999999
907199999990928000
8870399999991129600
535919999999464080
54999999999945
666
333
1110
333
22399997760
33599996640
3599964
6666600
333333000
5333280
56661
73326
Darko
Guru
Posts: 580 Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada
Post
by Darko » Sat Sep 16, 2006 6:00 pm
My AC program gives the same output - check if your operations are in wrong order and cause overflow or something like that.
jbh
New poster
Posts: 4 Joined: Fri Aug 04, 2006 7:33 pm
Post
by jbh » Sat Sep 16, 2006 7:19 pm
Darko wrote: My AC program gives the same output - check if your operations are in wrong order and cause overflow or something like that.
thnx for your reply. but i can't find the problem.
Can anyone debug my code?...
Last edited by
jbh on Fri Oct 20, 2006 2:44 pm, edited 1 time in total.
nymo
Experienced poster
Posts: 149 Joined: Sun Jun 01, 2003 8:58 am
Location: :)
Post
by nymo » Fri Oct 20, 2006 8:13 am
I 've tried all the test cases of this thread. But still getting WA. Can someone please post some more IO? thanks.
[EDIT]
I 've found the problem... unsigned long long is supposed to be printed with %llu ..... I was trying something like %ulld [oops, don't know why this comes to my mind]
... and that attemp survived without being a Compile Error, it was WA
... anyway, thanks.
sakhassan
Experienced poster
Posts: 105 Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU
Post
by sakhassan » Sun Oct 22, 2006 8:21 pm
i am getting WA ?? can any buddy help me what's wrong
Code: Select all
#include<stdio.h>
#include<string.h>
#include<math.h>
#define N 1000
double per(char a[N])
{
int de[N]={0};
int ss[300]={0};
int len;
int i,j;
double c,d;
len = strlen(a);
j=0;
c=1.0;
d=1.0;
for(i=0;i<len;i++)
{
ss[a[i]]++;
if(ss[a[i]]>1)
de[j++]=ss[a[i]];
}
c = 1.0;
for(i=2;i<=len;i++)
{
c*=i;
if(j>0)
d *=de[--j];
if( (d!=1) && !(fmod(c,d)) )
{
c/=d;
d=1;
}
}
return c;
}
int main()
{
int n;
int i;
char str[N],a[N];
double ans,col,num;
long sum;
int len;
while(1)
{
scanf("%d",&n);
if(n==0)
break;
strcpy(str,"");
for(i=0;i<n;i++)
{
scanf("%s",a);
strcat(str,a);
}
num = per(str);
len = strlen(str);
num/=len;
sum = 0;
for(i=0;i<len;i++)
{
sum += str[i]-'0';
}
col = ((double)sum) * num;
ans = 0.0;
for(i=0;i<len;i++)
{
ans *= 10.0;
ans += col;
}
printf("%.0lf\n",ans);
}
return 0;
}
rio
A great helper
Posts: 385 Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan
Post
by rio » Sun Oct 22, 2006 10:08 pm
it seems its overflowting. try this test code.
12
0 1 2 3 4 5 6 7 8 9 9 9
0
the answer should be 9676111852534327168 .
---
sory for my poor english. (*
sakhassan
Experienced poster
Posts: 105 Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU
Post
by sakhassan » Mon Oct 23, 2006 11:44 am
How can i overcome the overflow ?? my circuit is not working
helloneo
Guru
Posts: 516 Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea
Post
by helloneo » Mon Oct 23, 2006 11:54 am
sakhassan wrote: How can i overcome the overflow ?? my circuit is not working
I used "unsigned long long" and got AC..
sakhassan
Experienced poster
Posts: 105 Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU
Post
by sakhassan » Tue Oct 24, 2006 9:09 am
Thanks Buddy !! I got AC at last
annhy
New poster
Posts: 40 Joined: Sun May 27, 2007 1:42 am
Location: Taiwan
Post
by annhy » Wed Jun 27, 2007 7:54 am
rio wrote: it seems its overflowting. try this test code.
the answer should be 9676111852534327168 .
I use BigInteger in Java, and get the following result.
In fact, your test input will make the result bigger than 2^64 and overflow.
rio
A great helper
Posts: 385 Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan
Post
by rio » Wed Jun 27, 2007 8:10 am
Oops !
Your right. My values is overflowing.
The last digit can't be 8.. I missed it.
----
Rio