11340 - Newspaper

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

Post Reply
gr81
New poster
Posts: 46
Joined: Wed Sep 26, 2012 7:52 pm

Re: 11340 - Newspaper

Post by gr81 »

thanks brian...that's was kewl..
Ronok1307
New poster
Posts: 8
Joined: Tue May 29, 2012 7:37 pm

Re: 11340 - Newspaper

Post by Ronok1307 »

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.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11340 - Newspaper

Post by brianfry713 »

long long unsigned is %llu not %lld
Check input and AC output for thousands of problems on uDebug!
Ronok1307
New poster
Posts: 8
Joined: Tue May 29, 2012 7:37 pm

Re: 11340 - Newspaper

Post by Ronok1307 »

Changed that but still WA
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11340 - Newspaper

Post by brianfry713 »

PM sent, see my post from 12/19 about input parsing.
Check input and AC output for thousands of problems on uDebug!
Ronok1307
New poster
Posts: 8
Joined: Tue May 29, 2012 7:37 pm

Re: 11340 - Newspaper

Post by Ronok1307 »

Thanks a lot for the reply brianfry :)
Marcus43
New poster
Posts: 3
Joined: Fri Jan 11, 2013 7:19 am

Re: 11340 - Newspaper

Post by Marcus43 »

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.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11340 - Newspaper

Post by brianfry713 »

Change line 45 to:
value += dat[(unsigned char)po[j]];
Check input and AC output for thousands of problems on uDebug!
Marcus43
New poster
Posts: 3
Joined: Fri Jan 11, 2013 7:19 am

Re: 11340 - Newspaper

Post by Marcus43 »

Hey thanks... That was pretty tricky to detect
kier.guevara
New poster
Posts: 30
Joined: Thu Jul 19, 2012 11:24 pm

Re: 11340 - Newspaper

Post by kier.guevara »

Code: Select all

AC
I tried all the test case above and using unsigned char ang unsigned long long int but I still got WA..why?
Last edited by kier.guevara on Wed Feb 13, 2013 11:12 am, edited 1 time in total.
kier.guevara
New poster
Posts: 30
Joined: Thu Jul 19, 2012 11:24 pm

Re: 11340 - Newspaper

Post by kier.guevara »

Code: Select all

AC
I changed the last two digits after the dot as char.
Munchor
New poster
Posts: 19
Joined: Sun Mar 03, 2013 4:03 pm

Re: 11340 - Newspaper

Post by Munchor »

I am not even getting a correct output for the first example. My code:

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;
}
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?
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11340 - Newspaper

Post by brianfry713 »

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!
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11340 - Newspaper

Post by brianfry713 »

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!
Munchor
New poster
Posts: 19
Joined: Sun Mar 03, 2013 4:03 pm

Re: 11340 - Newspaper

Post by Munchor »

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;
}
Post Reply

Return to “Volume 113 (11300-11399)”