标签:include first 输出 ++ cstring cond for fine name
第一次使用map嵌套,做个纪念。
HDU 1263 水果
http://acm.hdu.edu.cn/showproblem.php?pid=1263
题解:按照地名的字典序、水果的字典序、水果的数量这个顺序输出。题意很简单,关键是用map嵌套。
代码:
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<cmath> 5 #include<algorithm> 6 #include<map> 7 #define ll long long 8 using namespace std; 9 10 const int N = 105; 11 12 map<string, map<string, int>, less<string> > q; 13 14 int main() 15 { 16 std::ios::sync_with_stdio(false); 17 int T; 18 cin >> T; 19 20 while (T--) 21 { 22 q.clear(); 23 int n, m; 24 char fruit[N], province[N]; 25 cin >> n; 26 for (int i = 0; i < n; i++) 27 { 28 cin >> fruit >> province >> m; 29 q[province][fruit] += m; 30 } 31 for (auto it = q.begin(); it != q.end(); it++) 32 { 33 cout << it->first << endl; 34 for (auto itt = (it->second).begin(); itt != (it->second).end(); itt++) 35 { 36 cout << " |----" << itt->first << "(" << itt->second << ")" << endl; 37 } 38 } 39 if (T) 40 cout << endl; 41 } 42 return 0; 43 }
标签:include first 输出 ++ cstring cond for fine name
原文地址:https://www.cnblogs.com/xiaohanghuo/p/11373761.html