~cpp #include <iostream> using namespace std; #include <fstream> #include <string> #include <vector> #include <algorithm> struct Word { string data; int count; int asciiSum; bool operator() (const Word* a, const Word* b) { if (a->data < b->data) return true; return false; } }; fstream fin("Alice.txt"); vector<Word*> container; void input() { Word* word; bool isFind; word = new Word; while(fin >> word->data) { isFind = false; for (int i = 0; i < container.size(); i++) { if (container[i]->data == word->data) { isFind = true; container[i]->count++; break; } } if (isFind == false) { word->asciiSum = 0; word->count = 1; container.push_back(word); } word = new Word(); } } // 2번 요구사항 void show() { for (int i = 0; i < container.size(); i++) cout << container[i]->data << ' ' << container[i]->count << ' ' << container[i]->asciiSum << endl; } // 3번 요구사항 void sortShow() { sort(&container[0], &container[container.size()], Word()); show(); } // 4번 요구사항 void cutString() { string temp; string newStr; for (int i = 0; i < container.size(); i++) { newStr = ""; temp = container[i]->data; for(int j = 0; j < temp.size(); j++) if (('A' <= temp[j] && temp[j] <= 'Z') || ('a' <= temp[j] && temp[j] <= 'z')) newStr += temp[j]; container[i]->data = newStr; } } // 5번 요구사항 void asciiCalc() { string temp; for (int i = 0; i < container.size(); i++) { temp = container[i]->data; for (int j = 0; j < temp.size(); j++) container[i]->asciiSum += int(temp[j]); } } void deleteVector() { Word *temp; for (int i = 0; i < container.size(); i++) { temp = container[i]; delete temp; } } int main() { input(); cutString(); asciiCalc(); sortShow(); deleteVector(); return 0; }