Блог пользователя Magellan

Автор Magellan, 15 лет назад, По-английски

Hi, 


There seems to be a problem with my submission... specifially with the first test:
3310
1033
When I compile and  run the program and give as an input the above, the output returned is
"OK"
But when I submit the problem to codeforces, the output is different....
"WRONG_ANSWER"
Can someone explain why is this happening?
I can't find anything wrong in my code either.

My code in C is here:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    char s[12], res[12], in[12];
    int k = 1, found = 0, i, j, mem[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    scanf("%s", &s);
    scanf("%s", &in);
    for(i = 1; i < 10; i++)
    {
          for(j = 0; j < strlen(s); j++)
          {
                if(s[j] == i + '0')
                {
                        res[0] = s[j];
                        mem[j] = 1;
                        found = 1;
                        break;
                }
          }
          if(found == 1)
               break;
    }
    for(i = 0; i < 10; i++)
    {
          for(j = 0; j < strlen(s); j++)
          {
                if(s[j] == i + '0' && mem[j] != 1)
                {
                        res[k] = s[j];
                        mem[j] = 1;
                        k++;
                }
          }
    }
    if(strcmp(res, in) == 0)
          printf("OK");
    else
          printf("WRONG_ANSWER");      
    return 0;
} 

Any help would be appreciated.
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

15 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +8 Проголосовать: не нравится
You should add 
 res[strlen(in)] = '\0'; 
 before comparing two strings.
But your implementation is wrong,  it fails test 
1000000000
1