U E D R , A S I H C RSS

Code Race/20060105/도현승한

codeRace/20060105
----
~cpp
#include <fstream>
#include <vector> 
#include <algorithm>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;

struct leonardong{
	int count;
	string word;
};

bool CompareObj(leonardong first, leonardong second )
{
	return first.word < second.word;
}

bool EqualObj(leonardong first, leonardong second )
{
	return first.word == second.word;
}

void showStrVec(vector<string>& aVec)
{
	for (int i = 0; i < aVec.size(); i++)
		cout << aVec[i] << endl;
	/*
	for(vector<string>::iterator iter = aVec.begin(); iter!=aVec.end(); iter++)
		cout<<(*iter);
	*/
	return;
}

void showLeoVec(vector<leonardong>& aVec)
{
	for (int i = 0; i < aVec.size(); i++)
		cout << aVec[i].word << " " << aVec[i].count << endl;
	/*
	for(vector<string>::iterator iter = aVec.begin(); iter!=aVec.end(); iter++)
		cout<<(*iter);
	*/
	return;
}

int findWord(vector<leonardong>& findVec, string str)
{
	for (int i = 0; i < findVec.size(); i++)
	{
		if (findVec[i].word == str)
			return i;
	}
	return -1;
}

string clearString(string str)
{
	//알파벳이 아닌 다른 문자를 없애버린다.
	int index = 0;
	string temp;
	for (int i = 0; i < str.size(); i++)
	{
		if (isalpha(str[i]) == true)
		{
		}
	}
	return temp;
}

void inputVec(vector<string>& aVec1, vector<leonardong>& aVec2){
	ifstream fin("input.txt");
	string str;
	int vecIndex = 0;

	while (!fin.eof())
	{
		fin >> str;
		aVec1.push_back(str);

		str = clearString(str);

		leonardong struct_str;
		struct_str.count = 1;
		struct_str.word = str;
		
		vecIndex = findWord(aVec2, str);
		// search
		if(vecIndex != -1)
		{
			//카운트를 늘려준다.
			aVec2[vecIndex].count++;	
		}
		else
		{
			aVec2.push_back(struct_str);
		}
		
	}

	// sort
	sort(aVec2.begin(), aVec2.end(), CompareObj);		// 오름차순
}

//int findWordN(vec, str);
void main()
{
	vector<string> totalInput;
	vector<leonardong> noDupInput;

	inputVec(totalInput, noDupInput);
	
	//showStrVec(totalInput); //요구사항 1
	showLeoVec(noDupInput);
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:54
Processing time 0.0094 sec