二维map —— HDU1263
生活随笔
收集整理的這篇文章主要介紹了
二维map —— HDU1263
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
水果
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8752 Accepted Submission(s): 3482Problem Description
夏天來了~~好開心啊,呵呵,好多好多水果~~ Joe經(jīng)營著一個不大的水果店.他認為生存之道就是經(jīng)營最受顧客歡迎的水果.現(xiàn)在他想 要一份水果銷售情況的明細表,這樣Joe就可以很容易掌握所有水果的銷售情況了.Input
第一行正整數(shù)N(0<N<=10)表示有N組測試數(shù)據(jù). 每組測試數(shù)據(jù)的第一行是一個整數(shù)M(0<M<=100),表示工有M次成功的交易.其后有M行 數(shù)據(jù),每行表示一次交易,由水果名稱(小寫字母組成,長度不超過80),水果產(chǎn)地(小寫字 母組成,長度不超過80)和交易的水果數(shù)目(正整數(shù),不超過100)組成.Output
對于每一組測試數(shù)據(jù),請你輸出一份排版格式正確(請分析樣本輸出)的水果銷售情況明 細表.這份明細表包括所有水果的產(chǎn)地,名稱和銷售數(shù)目的信息.水果先按產(chǎn)地分類,產(chǎn)地 按字母順序排列;同一產(chǎn)地的水果按照名稱排序,名稱按字母順序排序. 兩組測試數(shù)據(jù)之間有一個空行.最后一組測試數(shù)據(jù)之后沒有空行.Sample Input
1 5 apple shandong 3 pineapple guangdong 1 sugarcane guangdong 1 pineapple guangdong 3 pineapple guangdong 1Sample Output
guangdong|----pineapple(5)|----sugarcane(1) shandong|----apple(3)本題主要練習二維map的建立與遍歷,重點注意在遍歷第二維時,應用iter = it->second.first(),也就是_map鍵值對中的值map<string, int>,而不是iter = it.first()
#include <iostream> #include <string> #include <map> using namespace std;int main() {int n, m, x;string place, fruit;cin >> n;while( n-- ) {map< string, map< string, int > > _map;cin >> m;while( m-- ) {cin >> fruit >> place >> x;_map[place][fruit] += x;}map< string, map< string, int > > ::iterator it;for( it = _map.begin(); it != _map.end(); it++ ) {cout << it->first << endl;map< string, int > ::iterator iter;for( iter = it->second.begin(); iter != it->second.end(); iter++ ) {cout << " |----" << iter->first << '(' << iter->second << ')' << endl;}}if ( n ) {cout << endl;}}return 0; }總結(jié)
以上是生活随笔為你收集整理的二维map —— HDU1263的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: I/O复用之 EPOLLONESHOT
- 下一篇: react 因为this.setStat