Created
September 23, 2012 00:08
-
-
Save HappyCerberus/3768301 to your computer and use it in GitHub Desktop.
Vzorové řešení programu "frekvence cisel"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unordered_map> | |
#include <algorithm> | |
#include <iterator> | |
#include <iostream> | |
using namespace std; | |
int main(int argc, char *argv[]) | |
{ | |
unordered_map<int,int> freq; | |
istream_iterator<int> input(cin); | |
istream_iterator<int> eof; | |
if (argc == 2 && argv[1] == string("--cifry")) | |
{ | |
for_each(input, eof, [&] (int x) | |
{ while (x != 0) { freq[x%10]++; x/=10; } }); | |
} | |
else if (argc == 1) | |
{ | |
for_each(input, eof, [&] (int x) | |
{ freq[x]++; }); | |
} | |
else | |
{ | |
cerr << "Tento program ocekava jeden volitelny parametr: \"--cifry\"" << endl; | |
return 1; | |
} | |
cout << "Frekvence:" << endl; | |
for(auto i : freq) | |
{ | |
cout << "\"" << i.first << "\"" << " " << i.second << "x" << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment