1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <iostream> #include <map> #include <string> using namespace std; int main( void ) { map<string, int > maplist; string word; while (cin >> word) maplist[word]++; for (map<string, int >::iterator iter = maplist.begin(); iter != maplist.end(); iter++) cout << iter->first << '\t' << iter->second << endl; return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include <iostream> #include <string> #include <map> #include <vector> #include <algorithm> using namespace std; bool splitblank( const string str, map<string, int > &result); int main( void ) { int wordline = 0; string searchword; string statement; map<string, int > result; cin >> wordline; //버퍼가 안비워져서 getline에 개행문자가 들어감 cin.ignore(); for ( int i = 0;i<wordline;i++) { getline(cin, statement); splitblank(statement, result); } cin >> searchword; cout << result[searchword] << endl; return 0; } bool splitblank( const string str, map<string, int > &result) { if (str.size() == 0 ) return false ; string::size_type index = 0; string::size_type start = 0; string::size_type strsize = str.size(); for (; index <= strsize; index++) { if ( isspace (str[index]) || strsize == index) { result[str.substr(start, index-start)]++; start = ++index; } } return true ; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include <iostream> #include <map> #include <algorithm> #include <string> #include <vector> using namespace std; bool splitblank( const string str, map< string, vector< int > > &result, int wordline); int main( void ) { string statement; int wordline = 0; map< string, vector< int > > table; while (getline(cin, statement)) { splitblank(statement, table, ++wordline); } for (map< string, vector< int > >::iterator mapiter = table.begin(); mapiter != table.end(); mapiter++) { cout << mapiter->first << " : " ; for (vector< int >::iterator vectiter = mapiter->second.begin(); vectiter != mapiter->second.end(); vectiter++) { cout << *vectiter; if (mapiter->second.end() != (vectiter + 1)) cout << ", " ; } cout << endl; } return 0; } bool splitblank( const string str, map< string, vector< int > > &result, int wordline) { if (str.size() == 0 ) return false ; string::size_type index = 0; string::size_type start = 0; string::size_type strsize = str.size(); for (; index <= strsize; index++) { if ( isspace (str[index]) || strsize == index) { result[str.substr(start, index-start)].push_back(wordline); start = ++index; } } return true ; }<p></p> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <iostream> #include <algorithm> #include <vector> using namespace std; bool iseven( int i) { return ((i%2)==0); } int main( void ) { int a; vector< int > list; vector< int >::iterator it; while (cin >> a) list.push_back(a); it = find_if(list.begin(), list.end(), iseven); (it == list.end()) ? a = 0 : a = *it; cout << a << endl; return 0; }<p></p> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <iostream> #include <map> #include <string> using namespace std; int main( void ) { string national; int code; map<string, int > codeTable; cin.clear(); while (cin >> national >> code) { codeTable[national] = code; } cin.clear(); while (cin >> national) { if (codeTable[national] == 0) cout << "not exist" << endl; else cout << national << ' ' << codeTable[national] << endl; } cin.clear(); return 0; }<p></p> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include <iostream> #include <string> #include <algorithm> using namespace std; int main( void ) { int wordCount = 0; int paliCount = 0; string word; cin >> wordCount; for ( int i = 0; i < wordCount; i++) { cin >> word; string temp(word); reverse(temp.begin(), temp.end()); if (equal(word.begin(), word.end(), temp.begin())) paliCount++; } cout << paliCount << endl; return 0; } <p></p> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include <iostream> #include <algorithm> #include <map> #include <vector> #include <string> using namespace std; bool splitBlank( const string str, vector<string> &result); int main( void ) { int count = 0; char rome; string mos; string message; map< char , string> mosTable; for (;count<=25;count++) { cin >> rome >> mos; mosTable[rome] = mos; } cin.ignore(); getline(cin, message); //splitBlank(message, parseVector); for (string::iterator i = message.begin(); i != message.end(); i++) cout << mosTable[*i] << ' ' ; cout << endl; return 0; }<p></p> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #include <iostream> #include <algorithm> #include <map> #include <vector> #include <string> using namespace std; bool splitBlank( const string str, vector<string> &result); int main( void ) { int count = 0; string mos; string rome; string message; vector<string> parseVector; map<string, string> mosTable; for (;count<=25;count++) { cin >> rome >> mos; mosTable[mos] = rome; } cin.ignore(); getline(cin, message); splitBlank(message, parseVector); for (vector<string>::iterator i = parseVector.begin(); i != parseVector.end(); i++) cout << mosTable[*i]; cout << endl; return 0; } bool splitBlank( const string str, vector<string> &result) { if (str.size() == 0 ) return false ; string::size_type index = 0; string::size_type start = 0; string::size_type strSize = str.size(); for (; index <= strSize; index++) { if ( isspace (str[index]) || index == strSize) { result.push_back(str.substr(start, index-start)); start = ++index; } } return true ; }<p></p> |
Posted by LaLuna