Page 7 of 11

Re: 11340 - Newspaper

Posted: Thu Dec 20, 2012 7:22 am
by gr81
thanks brian...that's was kewl..

Re: 11340 - Newspaper

Posted: Sun Dec 23, 2012 2:10 am
by Ronok1307
Getting WA

Code: Select all

Removed after AC

Re: 11340 - Newspaper

Posted: Sat Dec 29, 2012 10:05 pm
by brianfry713
long long unsigned is %llu not %lld

Re: 11340 - Newspaper

Posted: Sun Dec 30, 2012 8:30 pm
by Ronok1307
Changed that but still WA

Re: 11340 - Newspaper

Posted: Tue Jan 01, 2013 2:54 am
by brianfry713
PM sent, see my post from 12/19 about input parsing.

Re: 11340 - Newspaper

Posted: Tue Jan 01, 2013 5:55 pm
by Ronok1307
Thanks a lot for the reply brianfry :)

Re: 11340 - Newspaper

Posted: Fri Jan 11, 2013 7:22 am
by Marcus43
Getting WA:

Code: Select all

REMOVED AFTER AC

Re: 11340 - Newspaper

Posted: Fri Jan 11, 2013 8:45 pm
by brianfry713
Change line 45 to:
value += dat[(unsigned char)po[j]];

Re: 11340 - Newspaper

Posted: Sat Jan 12, 2013 3:33 am
by Marcus43
Hey thanks... That was pretty tricky to detect

Re: 11340 - Newspaper

Posted: Wed Feb 13, 2013 10:08 am
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?

Re: 11340 - Newspaper

Posted: Wed Feb 13, 2013 10:35 am
by kier.guevara

Code: Select all

AC
I changed the last two digits after the dot as char.

Re: 11340 - Newspaper

Posted: Wed Mar 13, 2013 4:30 pm
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?

Re: 11340 - Newspaper

Posted: Wed Mar 13, 2013 9:55 pm
by brianfry713
For one thing, you should use scanf("%u") to read an unsigned int and scanf("%hhu") to read an unsigned char.

Re: 11340 - Newspaper

Posted: Wed Mar 13, 2013 9:58 pm
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);
...

Re: 11340 - Newspaper

Posted: Wed Mar 13, 2013 11:49 pm
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;
}