11340 - Newspaper
Moderator: Board moderators
Re: 11340 - Newspaper
thanks brian...that's was kewl..
Re: 11340 - Newspaper
Getting WA
Code: Select all
Removed after AC
Last edited by Ronok1307 on Tue Jan 01, 2013 5:53 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11340 - Newspaper
long long unsigned is %llu not %lld
Check input and AC output for thousands of problems on uDebug!
Re: 11340 - Newspaper
Changed that but still WA
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11340 - Newspaper
PM sent, see my post from 12/19 about input parsing.
Check input and AC output for thousands of problems on uDebug!
Re: 11340 - Newspaper
Thanks a lot for the reply brianfry ![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
Re: 11340 - Newspaper
Getting WA:
Code: Select all
REMOVED AFTER AC
Last edited by Marcus43 on Sat Jan 12, 2013 3:33 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11340 - Newspaper
Change line 45 to:
value += dat[(unsigned char)po[j]];
value += dat[(unsigned char)po[j]];
Check input and AC output for thousands of problems on uDebug!
Re: 11340 - Newspaper
Hey thanks... That was pretty tricky to detect
-
- New poster
- Posts: 30
- Joined: Thu Jul 19, 2012 11:24 pm
Re: 11340 - Newspaper
Code: Select all
AC
Last edited by kier.guevara on Wed Feb 13, 2013 11:12 am, edited 1 time in total.
-
- New poster
- Posts: 30
- Joined: Thu Jul 19, 2012 11:24 pm
Re: 11340 - Newspaper
Code: Select all
AC
Re: 11340 - Newspaper
I am not even getting a correct output for the first example. My code:
For the example IO, I am getting 3.51$ as output which is close to 3.74$ actually, so I must be doing something very wrong. I tried using STL's map instead of an array too, but I got the exact same output.
I have also debugged by printing out all the characters I'm reading and the input seems to be done correctly, so I can't quite see what's wrong.
Any ideas?
Code: Select all
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
unsigned int n, i, k, u, temp_value, m, final_value = 0;
unsigned char temp_char;
unsigned char values[1000];
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d", &k);
memset(values, 0, sizeof values);
final_value = 0;
for (u = 0; u < k; u++)
{
scanf(" %c %d", &temp_char, &temp_value);
values[temp_char] += temp_value;
}
scanf("%d", &m);
for (u = 0; u < m; u++)
{
while (true)
{
scanf("%c", &temp_char);
if (temp_char == '\n')
{
break;
}
final_value += values[temp_char];
}
}
printf("%.2f$\n", (float) final_value / 100);
}
return 0;
}
I have also debugged by printing out all the characters I'm reading and the input seems to be done correctly, so I can't quite see what's wrong.
Any ideas?
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11340 - Newspaper
For one thing, you should use scanf("%u") to read an unsigned int and scanf("%hhu") to read an unsigned char.
Check input and AC output for thousands of problems on uDebug!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11340 - Newspaper
brianfry713 wrote:Change the way you parse the input. Here's what I did to get AC in ANSI C:Code: Select all
unsigned char c, line[10010]; int val; ... gets(line); sscanf(line,"%c %d",&c,&val); ...
Check input and AC output for thousands of problems on uDebug!
Re: 11340 - Newspaper
I fixed my unsigned chars to:
Code: Select all
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
unsigned int n, i, k, u, temp_value, m, final_value = 0;
char temp_char;
int values[1000];
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d\n", &k);
memset(values, 0, sizeof values);
final_value = 0;
for (u = 0; u < k; u++)
{
scanf("%c %d\n", &temp_char, &temp_value);
values[temp_char] += temp_value;
}
scanf("%d", &m);
getchar();
for (u = 0; u < m; u++)
{
while (true)
{
scanf("%c", &temp_char);
if (temp_char == '\n')
{
break;
}
final_value += values[temp_char];
}
}
printf("%.2lf$\n", (double) final_value / 100);
}
return 0;
}