10338 - Mischievous Children
Moderator: Board moderators
-
- New poster
- Posts: 9
- Joined: Tue Apr 01, 2003 10:03 pm
- Location: Dhaka, Bangladesh
Why I always get WA????????
[c]#include<stdio.h>
#define SIZE 20
struct letter{
char chr;
int freq;
};
struct letter in[SIZE];
char str1[20000];
unsigned long long i,j,flag,countStruct,n,k,sum,cur;
unsigned long long fact(unsigned long long d)
{
unsigned long long s,b;
s=1;
for(b=1;b<=d;b++)
s *= b;
return s;
}
void swap(char *a, char *b)
{
*a = *a + *b - (*b=*a);
}
void initAll()
{
int i;
for(i=0;i<SIZE;i++)
in.chr=-1,in.freq=0;
}
void main(void)
{
scanf("%lld",&n);
k=0;
while(k<n)
{
scanf("%s",str1);
countStruct=0,initAll();
for(i=0;i<strlen(str1);i++)
{
flag=0;
for(j=0;j<=countStruct;j++)
{
if(in[j].chr==str1)
{
in[j].freq++;
flag=1;
break;
}
}
if(flag==0)
in[countStruct].chr=str1,in[countStruct].freq=1,countStruct++;
}
if(strlen(str1)==countStruct)
cur = fact(strlen(str1));
else
{
cur=0;
for(i=0;i<countStruct;i++)
if(in.freq>1)
cur += fact(in.freq);
cur = fact(strlen(str1))/cur;
}
printf("Data set %lld: %lld\n",k+1,cur);
k++;
}
}[/c]
Thanks!
[c]#include<stdio.h>
#define SIZE 20
struct letter{
char chr;
int freq;
};
struct letter in[SIZE];
char str1[20000];
unsigned long long i,j,flag,countStruct,n,k,sum,cur;
unsigned long long fact(unsigned long long d)
{
unsigned long long s,b;
s=1;
for(b=1;b<=d;b++)
s *= b;
return s;
}
void swap(char *a, char *b)
{
*a = *a + *b - (*b=*a);
}
void initAll()
{
int i;
for(i=0;i<SIZE;i++)
in.chr=-1,in.freq=0;
}
void main(void)
{
scanf("%lld",&n);
k=0;
while(k<n)
{
scanf("%s",str1);
countStruct=0,initAll();
for(i=0;i<strlen(str1);i++)
{
flag=0;
for(j=0;j<=countStruct;j++)
{
if(in[j].chr==str1)
{
in[j].freq++;
flag=1;
break;
}
}
if(flag==0)
in[countStruct].chr=str1,in[countStruct].freq=1,countStruct++;
}
if(strlen(str1)==countStruct)
cur = fact(strlen(str1));
else
{
cur=0;
for(i=0;i<countStruct;i++)
if(in.freq>1)
cur += fact(in.freq);
cur = fact(strlen(str1))/cur;
}
printf("Data set %lld: %lld\n",k+1,cur);
k++;
}
}[/c]
Thanks!
-
- Experienced poster
- Posts: 136
- Joined: Tue Apr 01, 2003 6:59 am
- Location: Jakarta, Indonesia
10338
Code removed after AC
-
- New poster
- Posts: 7
- Joined: Fri Sep 03, 2004 6:47 pm
10338 compile error
[cpp]
[/cpp]why it gives me compile error?
tell me please
#include <stdio.h>
#include <string.h>
void main()
{
long double fact[21],f=1,i,ans;
char word[22];
int l;
unsigned long set=1;
for(i=1;i<=20;i++)
{
f=f*i;
fact=f;
}
while(scanf("%s",word)==1)
{
int frec[26]={0};
l=strlen(word);
i=-1;
while(word[++i])
frec[word-65]++;
ans=fact[l];
for(i=0;i<26;i++)
if(frec>1)
ans=ans/fact[frec];
printf("Data set %lu: %.0Lf\n",set++,ans);
}
}
-
- Experienced poster
- Posts: 115
- Joined: Tue Apr 06, 2004 7:04 pm
- Location: Venezuela
Hi Gazi Shaheen Hossain, i compile with gcc in linux red hat, and in this lines
12, 20,21,24,25 the index is not a integer that the reason for the compile error
Hope it helps
Keep posting
P.S. if change the declaration of i to int give WA. if you want some inputs posted here your I/O and I give you the anwser of my AC code.
12, 20,21,24,25 the index is not a integer that the reason for the compile error
Hope it helps
Keep posting

P.S. if change the declaration of i to int give WA. if you want some inputs posted here your I/O and I give you the anwser of my AC code.
10338 WA...
Maybe I'm irresponsible, but I'd used the n!/(n1!*n2!...) algorithm and got WA. I don't dare to use long long so I check if the range was exceeded then pause and just start dividing, and once it's indivisible with a certain number then build up the remaining factorial, and so forth:
[c]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
unsigned long int o;
int charcount[26];
int main(int args, char **argv) {
int i, j, t, s, L, N;
unsigned long int r;
char in[20];
scanf("%d", &N);
for (i = 0; i < N; i++) {
for (j = 0; j < 26; j++) charcount[j] = 0;
scanf("%s", in);
L = strlen(in);
for (j = 0; j < L; j++) charcount[(in[j] - 65)]++;
r = 1;
j = 1;
do {
r *= j;
j++;
} while ((j <= L) && (4294967296 / r >= j));
t = j;
for (j = 0; j < 26; j++) {
s = 1;
while (s <= charcount[j]) {
if (r % s == 0) {
r /= s;
s++;
}
else while ((t <= L) && (4294967296 / r >= t)) {
r *= t;
t++;
}
}
}
while (t <= L) {
r *= t;
t++;
}
printf("Data set %d: %ld\n", i+1, r);
}
return 0;
}
[/c]
Actually I read earlier posts but I can't figure it out. Maybe somebody provide some testcases for me...
[/c]
[c]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
unsigned long int o;
int charcount[26];
int main(int args, char **argv) {
int i, j, t, s, L, N;
unsigned long int r;
char in[20];
scanf("%d", &N);
for (i = 0; i < N; i++) {
for (j = 0; j < 26; j++) charcount[j] = 0;
scanf("%s", in);
L = strlen(in);
for (j = 0; j < L; j++) charcount[(in[j] - 65)]++;
r = 1;
j = 1;
do {
r *= j;
j++;
} while ((j <= L) && (4294967296 / r >= j));
t = j;
for (j = 0; j < 26; j++) {
s = 1;
while (s <= charcount[j]) {
if (r % s == 0) {
r /= s;
s++;
}
else while ((t <= L) && (4294967296 / r >= t)) {
r *= t;
t++;
}
}
}
while (t <= L) {
r *= t;
t++;
}
printf("Data set %d: %ld\n", i+1, r);
}
return 0;
}
[/c]
Actually I read earlier posts but I can't figure it out. Maybe somebody provide some testcases for me...

-
- Learning poster
- Posts: 94
- Joined: Wed Jul 31, 2002 12:44 pm
- Location: Dacca, Bangladesh
- Contact:
hi,
well, unsigned long's should be printed using %lu, isn't it?
1) it should be 294967295 ( 2^32-1) OR
2) cast 294967296 to long long ( no need of big guts to use long long here
) using 294967296ll [ 294... ell,ell] instead of 294967296.
thank you.
then char in[20]; should be char in[21]; ( one extra for 0 termination, blah blah)Each word will have at most 20 letters.
Code: Select all
printf("Data set %d: %ld\n", i+1, r);
Now, 294967296 = 2^32, which does not fit in even unsigned long, so...TWEmp wrote:294967296 / r
1) it should be 294967295 ( 2^32-1) OR
2) cast 294967296 to long long ( no need of big guts to use long long here

thank you.
Istiaque Ahmed [the LA-Z-BOy]
10338 -->Why WA
Hi,
Can enyone tell me what is wrong with my code. Output seems Ok.
THANKS!!
Can enyone tell me what is wrong with my code. Output seems Ok.
Code: Select all
Code removed after ACC..
Last edited by p!ter on Sat Jan 15, 2005 5:50 pm, edited 1 time in total.
-
- New poster
- Posts: 43
- Joined: Mon Oct 13, 2003 4:54 pm
- Location: Mexico
- Contact:
Code: Select all
:D perdon
Last edited by lord_burgos on Mon Jan 17, 2005 9:04 am, edited 1 time in total.