494 WA

All about problems in Volume IV. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

494 WA

Postby refa » Mon Apr 11, 2005 11:33 pm

Dear ACM members,

Could you please take a look at my code and tell me what's wrong because I am getting WA all the time and I read all the posts about it on the forum and it works properly with the example inputs. Thank you

Code: Select all
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

int main()
{
  string line1="";
  long long int duzina=0;
  long long int count = 0;
  while(getline(cin, line1))
  {
    duzina= 0;
    count = 0;

    line1= " " + line1 + " ";
     for(long long int i=0; i<line1.length(); i++)
     {
      if(ispunct(line1[i])!=0 || isspace(line1[i])!=0 || isdigit(line1[i])!=0 || isblank(line1[i])!=0 || iscntrl(line1[i])!=0)
      {
       string word = "";
       word = line1.substr(duzina, i-duzina);
       if(isalpha(word[0]))
       {
           count++;
        }

       duzina=i+1;
      }
     }
    cout << count <<endl;
  };
  return 0;
};


I hope somebody will be able to help me out. Thx :)

Best regards,
Refik
refa
New poster
 
Posts: 8
Joined: Thu Mar 17, 2005 9:00 pm

Postby jaracz » Fri May 27, 2005 12:31 am

consider this algo

read string
if(isalpha(string[0]))count++;

and than in some loop until the one before last element of string(excluding '\0')

if( (isspace(string[i]) && isalpha(string[i+1])) || (!isspace(string[i]) && !isalpha(string[i])) && isalpha(string[i+1]) ) count++;

and you dont have to use long long( i used just int )
Hope it helps!
keep it real!
User avatar
jaracz
Learning poster
 
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland


Return to Volume IV

Who is online

Users browsing this forum: No registered users and 0 guests