⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3-3.cpp

📁 Accelerted cpp 第三章答案 (部分) 一本很好的cpp入门书
💻 CPP
字号:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using std::cin; 	using std::cout;
using std::endl;	using std::string;
using std::sort;    using std::vector;

int main()
{
	cout << "Please enter some words:" <<endl;
	string word;
	vector<string> words;
	
	while(cin >> word)
	words.push_back(word);
	cout << endl;

	sort(words.begin(),words.end());
	vector<double>::size_type number = words.size();
	
	if (number == 0) {
	    cout << "You didn't enter any words."
		    "Please try again."<<endl;
	    return 1;
	    }	
	
	int count = 1;
	int n = 0;
	while(n != number) {
	    n ++;
	    if(words[n] == words[n - 1]) 
	       count ++;	
	    else {
	       cout << "The string \"" << words[n-1] << "\" emerges " 
                    << count << "times." <<endl;
		    count = 1;
		 }
    }
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -