Created
November 7, 2014 18:39
-
-
Save rmccullagh/bf5d27df5e86c2b486c6 to your computer and use it in GitHub Desktop.
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 <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