SOJ.Letters and Words

                                                                                Letters and Words
 
     
 
時間限制:1秒    內存限制:256兆
題目描述

Calculate the number of letters (including white spaces but excluding line breaks) and the number of words in the given paragraph. 

The input consists of only alphabets and white spaces.

樣例輸入
Hello world
 Welcome to SYSU
a a  a
樣例輸出
Letters: 33
Words: 8
提示

Use cin.get() to read the paragraph. 

Use istringstream strm(string) to obtain a string stream. The string stream can help you to read all string blocks in a simple way.

沒什麼好介紹的,一道作業題。




#include
#include
#include
using namespace std;
int main()
{
	int word=0,letters=0;
	string str, line;
	while(getline(cin, line))//read the paragraph. 
	{
		for(int i=0;i<1000;i++){
			if(line[i]=='\0')break;
			letters++;//calculate the number of letters.
		}
		istringstream stream(line);//istringstream the line.
		while(stream>>str) word++;//calculate the number of word.
	}
	cout<<"Letters: "<

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章