4341 - Word Counting

Do you want to discuss about these problems? Go now!
Users are shared (no need to re-register).

Moderator: Board moderators

Post Reply
thuongkhanh
New poster
Posts: 2
Joined: Tue Jul 12, 2011 5:28 pm

4341 - Word Counting

Post by thuongkhanh » Fri Sep 09, 2011 11:25 am

Hi All

I 'm a beginner in ACM contest. I have completed this problem :
http://acm.uva.es/archive/nuevoportal/d ... php?p=4341

I run sample input in my pc, it showed the correct output. But when I submit, the result is "RUN TIME ERROR"
Would you like to review my code for me?

This is my code

Code: Select all

#include <stdio.h>
#include <string.h>

int main()
{
    int n;
    int count = 1;
    int dem = 0;
    int pre = -1;
    int max = -1;
    int val;
    char c;
    int flag = 0;
    char *st;
    char *temp;
    scanf("%d%c",&n,&c);
    while (count<=n)
    {
          gets(st);
          count++;
          temp = strtok(st," ");
          while (temp)
          {
              val = strlen(temp);
              if (pre == -1)
                 {
                          pre = val;
                          dem = 1;
                 }
              else  
              {
                    if (val == pre)
                    {
                       dem++;
                       
                    }
                    else
                    {
                        if (dem > max)
                           max = dem;
                        dem = 1;
                        pre = val;
                    }
              }
              temp = strtok(NULL," ");
          }
          
          if (dem > max)
             max = dem;
          printf("%d\n",max);
          max = 0;
          dem = 1;
          pre = -1;
          
    }

    return 0;
}


helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Re: 4341 - Word Counting

Post by helloneo » Fri Sep 09, 2011 3:10 pm

Try this

char st[300000]

instead of

char *st

Post Reply

Return to “ACM ICPC Archive Board”