去掉英文句子中重複出現的單詞和標點符號

#include "stdafx.h"
#include "iostream"
#include "sstream"
#include "map"
#include "string"
#include "list"
#include "vector"
#include <cctype>
using namespace std;


int main()
{
	string inputstr;
	string str;
	getline(cin,inputstr);
	string::size_type index=0;
	for (index = 0;index != inputstr.size();index++)
	{
		if(ispunct(inputstr[index]))
		{
			inputstr[index] = ' ';
		}
	}
	istringstream stream(inputstr);

	vector<string> svec;
	vector<string>::iterator isvec;
	bool find = false;
	while (stream>>str)
	{
		find = false;
		for (isvec = svec.begin(); isvec != svec.end();isvec++)
		{
			if (*isvec == str)
			{
				find = true;
			}
		}
		if (find == false)
		{

			svec.push_back(str);
		}
	}
	for (isvec = svec.begin(); isvec != svec.end();isvec++)
		cout<<*isvec<<" ";
	cout<<endl;
}


 

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