Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
unordered_map
// map #include <iostream> #include <unordered_map> #include <string> #include <utility> #include <algorithm> #include <iterator> using namespace std; enum emonths{january, february, march, april, may, june, july, august, september, october, november, december}; string smonth[12] ={"january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"}; typedef unordered_map<string, int>umap; umap days_in_month(){ umap um; um.insert(make_pair(smonth[january], 31)); um.insert(make_pair(smonth[february], 28)); um.insert(make_pair(smonth[march], 31)); um.insert(make_pair(smonth[april], 30)); um.insert(make_pair(smonth[may], 31)); um.insert(make_pair(smonth[june], 30)); um.insert(make_pair(smonth[july], 31)); um.insert(make_pair(smonth[august], 31)); um.insert(make_pair(smonth[september],30)); um.insert(make_pair(smonth[october], 31)); um.insert(make_pair(smonth[november], 30)); um.insert(make_pair(smonth[december], 31)); return um; }; int main() { umap m2; m2 = days_in_month(); umap::const_iterator diter; cout << "months with 30 days\n____________________\n\n"; for(int i = january; i<(december+1); i++){ diter = m2.find(smonth[i]); if((*diter).second == 30) cout << (*diter).first << "\n"; } cout << "\nmonths with 31 days\n____________________\n\n"; for(int i = january; i<(december+1); i++){ diter = m2.find(smonth[i]); if((*diter).second == 31) cout << (*diter).first << "\n"; } diter = m2.find(smonth[february]); cout << "\n" << diter->first << " has " << diter->second << " days; "; cout << "unless its a leap year.\n"; return 0; }
run
|
edit
|
history
|
help
0
Shortest Non Common Subsequence
MovConstrAssign
Dar
wealth of banks
reverse function
logcOperator
Default copy
11933
Dar
Two-phase sample with GCC