at last solve 494
Posted: Tue Dec 23, 2003 9:00 am
hi everybody at last i solve this problem.i only change char t[30000].
Code: Select all
#include <iostream>
using namespace std;
char buff;
int words;
bool is;
int main() {
while(!cin.eof()) {
buff = cin.get();
while(buff!='\n' && buff!=EOF) {
if( ( buff >= 'a' && buff <= 'z') || (buff >= 'A' && buff <= 'Z') ) {
if(!is) {
is = true;
words++;
}
}
else is = false;
buff = cin.get();
}
cout << words << endl;
words = 0;
is = false;
}
return 0;
}
Currently, your program will still parse the EOF, and thus output an extraneous "0".word1 word2(\n)
(EOF)
Code: Select all
#include<iostream>
#include<string>
#include<cstring>
using std::string;
using std::cout;
using std::endl;
using std::cin;
using std::getline;
string ip;
int p1,p2;
int count;
void word_check(string word)
{
char lc=word[word.length()-1]; //lc=last character.
if(word.length()!=1)
if(lc=='.'||lc=='?'||lc=='!')
word.erase(word.length()-1,1); //I just ignore the last character if its length is >1
int f=1;
for(int c1=0;c1<word.length();c1++)
if( !((word[c1]>='A'&&word[c1]<='Z') || (word[c1]>='a'&&word[c1]<='z')) )
{f=0;break;} //I defined word which has all its character between A->z or a->z
if(f)count++;
}
int main()
{
while(getline(cin,ip))
{
count=0;
p1=p2=0;
while(1)
{
while(p1<ip.length()&&ip[p1]==' ')p1++;p2=p1;
if(p1>=ip.length())break;
while(p2<ip.length()&&ip[p2]!=' ')p2++;
word_check(ip.substr(p1,p2-p1));
p1=p2;
}
cout<<count<<endl;
}
return 0;
}
Code: Select all
/*BEGIN_OF_THE_SOURCE_CODE*/
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define N 10000
int main()
{
char str[N];
int i,len,word = 0,j;
while(gets(str) != NULL)
{
word = 0;
len = strlen(str);
for(i = 0;i<len;i++)
{
if( isalpha(str[i]) )
{
for(j = i+1;j<len;j++)
{
if(str[j] == ' ' || str[j] =='\t')
{
word++;
break;
}
}
if(j == len )
word++;
i = j;
}
}
printf("%d\n",word);
}
return 0;
}
/*END_OF_THE_SOURCE_CODE*/
Code: Select all
abc@def
000a1b2c3d010
ch33se
Code: Select all
2
4
2
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;
};
Code: Select all
/*
Name: kindergarden countiog
Number: 494
Type : adhoc
Process : ON
Author :Salman Zaman
Email : zamansalman@gmail.com
Date : 21/08/05 23:27
*/
#include<stdio.h>
//#include<string.h>
//#include<conio.h>
int main(){
char ch;
int flag,count;
// freopen("494.txt","r",stdin);
flag=0;
count=0;
while(scanf("%c",&ch)!=EOF){
if((ch>='A' && ch<='Z' )||(ch>='a' && ch<='z')){
flag++;
}
else if(ch=='\n'){
if(flag>0){
count++;
}
printf("%d\n",count);
flag=0;
count=0;
}
else if(ch==' '){
if(flag>0){
count++;
}
flag=0;
}
}
//getch();
return 0;
}
Code: Select all
abcd-efg
Code: Select all
#include <string>
#include <iostream>
#include <cctype>
//#include <iomanip>
using namespace std;
int main()
{
string linha, cur_word;
int count, char_count;
while(getline(cin, linha))
{
count = 0;
char_count = 0;
cur_word.clear();
while(char_count < linha.size())
{
while(linha[char_count] != ' ' && char_count < linha.size())
{
cur_word += linha[char_count];
char_count++;
}
for(int i = 0; i < cur_word.size(); i++)
if(isalpha(cur_word[i]))
{
count++;
break;
}
cur_word.clear();
char_count++;
}
cout<<count<<endl;
}
return 0;
}
Code: Select all
cur_word.clear();