Tuesday, February 5, 2008

Kindergarten Counting Game : Problem No. 494

Submitted solution with Run Time = 0.000

#include<iostream>
#include<string>

using namespace std;

int main()
{
string str;
int i,count;

while(getline(cin,str))
{
i=0;
count=0;

while(str[i]!='\0')
{
if((str[i]>=65 && str[i]<=90) || (str[i]>=97 && str[i]<=122))
{
count++;
while((str[i]>=65 && str[i]<=90) || (str[i]>=97 && str[i]<=122))
{
i++;
}
}
i++;
}
cout<<count<<endl;
}

return 0;
}


Comment for better algorithm.

No comments: