[codeRace/20060105] ---- {{{~cpp #include #include #include #include #include #include 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& aVec) { for (int i = 0; i < aVec.size(); i++) cout << aVec[i] << endl; /* for(vector::iterator iter = aVec.begin(); iter!=aVec.end(); iter++) cout<<(*iter); */ return; } void showLeoVec(vector& aVec) { for (int i = 0; i < aVec.size(); i++) cout << aVec[i].word << " " << aVec[i].count << endl; /* for(vector::iterator iter = aVec.begin(); iter!=aVec.end(); iter++) cout<<(*iter); */ return; } int findWord(vector& 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& aVec1, vector& 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 totalInput; vector noDupInput; inputVec(totalInput, noDupInput); //showStrVec(totalInput); //요구사항 1 showLeoVec(noDupInput); } }}}