64,281
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{vector<string> vec;
string word;
while(cin>>word)
vec.push_back(word);
cout<<"输入单词个数为:"<<vec.size()<<endl;
return 0;
}
// LetterCount.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
void WorldCount(const char *sentence,int &count)
{
char c;
bool flag=true;
for(int i=0;(c=sentence[i])!='\0';i++)
{
if(c==' ' )
flag=true;
else if(flag==true)
{
flag=false;
count++;
}
}
}
int main(int argc, char* argv[])
{
char string[81];
gets(string);
int number=0;
WorldCount(string,number);
printf("There are %d words in the line.\n",number);
return 0;
}
#include<stdio.h>
int main()
{
char c[100];
int i = 0,count = 0;
gets(c);
while(c[i]!='\0')
{
while(c[i] == ' ')
i++;
if(c[i]!='\0')
count++;
while(c[i]!='\0'&&c[i]!=' ')
i++;
}
printf("the words:%d\n",count);
return 0;
}