Skip to content

Instantly share code, notes, and snippets.

@rmccullagh
Created November 7, 2014 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmccullagh/bf5d27df5e86c2b486c6 to your computer and use it in GitHub Desktop.
Save rmccullagh/bf5d27df5e86c2b486c6 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#define NL std::cout << std::endl
using namespace std;
void __(const char *s) {
std::cout << s << std::endl;
}
void print_map(const map<string, int> &m)
{
for(auto i = m.cbegin(); i != m.cend(); i++) {
const pair<string, int> &p = *i;
cout << p.first << ':' << p.second << endl;
}
}
int main()
{
map<string, int> m;
m["peach"]; m["apple"]; m["kiwifruit"]; m["pear"];
m["starfruit"]; m["grape"]; m["orange"];
m["pear"]++; m["apple"]++; m["pear"]++;
print_map(m);
cout << endl << endl;
string s("XxxX");
int cnt = count(s.begin(), s.end(), 'x');
cout << cnt << endl;
int cntif = count_if(s.begin(), s.end(), [](const char &s) {
return isupper(s);
});
cout << cntif << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment