C++ Bc. 27 cpp: Porovnání verzí
Bez shrnutí editace |
m Stránka C plus plus Bc. 27 cpp přemístěna na stránku C++ Bc. 27 cpp |
(Žádný rozdíl)
|
Verze z 2. 9. 2006, 09:20
#include <iostream> #include <sstream> #include <string> #include <set> typedef std::set<std::pair<std::string,int> > Konkordance; int main() { using namespace std; Konkordance K; int crad = 0; string radek; while (getline(cin, radek)) { crad++; for (int i=0; i<radek.length(); i++) { switch (radek[i]) { case '.': case ',': case ';': case '(': case ')': case '/': radek[i] = ' '; // nahradim znaky tecka, carka, atd. mezerou } } istringstream istr(radek); string slovo; while (istr >> slovo) { pair<string,int> p(slovo, crad); // dvojice <slovo, cislo radku> K.insert(p); // ulozim dvojici } } string t; for (Konkordance::const_iterator i=K.begin(), e=K.end(); i!=e; ++i) { const pair<string, int>& p = *i; if (t != p.first) cout << "\n" << p.first << " : " << p.second << " "; else cout << p.second << " "; t = p.first; } cout << "\n"; }
[ Zpět ]