Please suggest why my program run for more than 10 sec.
In my test case I have no problem ^_^
[cpp]
#include <stdio.h>
#include <string.h>
void main() {
int bean[26], guess[26];
int i, n, m, g[5], tp, tg;
char line[1001], c1, c[5];
double potcount;
scanf("%d", &n);
gets(line);
gets(line);
for (; n>0; n--) {
memset(bean, 0, 26*sizeof(int));
gets(line);
for (i=0; i<strlen(line); i++)
bean[line-'a']++;
memset(guess, 0, 26*sizeof(int));
tp=0;
tg=0;
while ((gets(line)!=NULL) && (line[0]!=0)) {
m=sscanf(line, "%c %c:%d,%c:%d,%c:%d,%c:%d,%c:%d", &c1, &c[0], &g[0], &c[1], &g[1], &c[2], &g[2], &c[3], &g[3], &c[4], &g[4]);
m=(m-1)/2;
for (i=0; i<m; i++) {
tg++;
if (g==bean[c-'a']) {
guess[c1-'A']+=2;
tp+=2;
}
if ((g==bean[c-'a']-1) || (g==bean[c-'a']+1)) {
guess[c1-'A']+=1;
tp++;
}
}
}
potcount=tg*2.0/tp;
for (i=0; i<26; i++)
if (guess!=0)
printf("%c %.2lf\n", (i+'A'), (potcount*guess));
if (n>1)
printf("\n");
}
}
[/cpp]
10390 - Bean Counting
Moderator: Board moderators
10390 - bean counting
Could somebody please verify the following I/O?
output:
The program works fine with the original data!
I already verified with assert that the first line is shorter than 8192 characters and that there's no scattered whitespace.
In first example possibly no one wins. I tried that alternative, printing just an empty line, WA, too!
Data types: int for guesses and shares, double for the winnings
Code: Select all
4
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
A a:0
Z a:0
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
A z:100
Z z:100
<- empty line (no beans at all)
A a:65
A s:0
Z a:1
a
A a:0
B a:1
C a:2
Code: Select all
A 2.00
Z 2.00
A 2.00
Z 2.00
A 4.00
Z 2.00
A 1.50
B 3.00
C 1.50
I already verified with assert that the first line is shorter than 8192 characters and that there's no scattered whitespace.
In first example possibly no one wins. I tried that alternative, printing just an empty line, WA, too!
Data types: int for guesses and shares, double for the winnings
Hi,
TRY CHANGING:
TO:
TRY CHANGING:
Code: Select all
scanf("%d", &n);
gets(line);
gets(line);
.
.
.
while ((gets(line)!=NULL) && (line[0]!=0))
{
}
Code: Select all
gets(line);
sscanf(line,"%d", &n);
gets(line);
.
.
.
while(gets(line))
{
if(strlen(line)==0) break;
}