#include <bits/stdc++.h> using namespace std; int main () { int a, b; cin >> a >> b; a += b; stack<int> s; bool flag = 0; while(abs(a) > 999) { s.push(abs(a) % 1000); a /= 1000; flag = 1; } cout << a; if(flag) { cout << ","; } int cap = s.size(); for(int i = 0; i < cap; ++i) { // cout << i << " 88888" << s.top() << endl; if(s.top() < 10) { cout << "00"; } else if(s.top() < 100) { cout << "0"; } cout << s.top(); if(i != cap - 1) { cout << ','; } s.pop(); } cout << endl; return 0; }
也可以用数组
#include <bits/stdc++.h> using namespace std; int main () { map<int, double, greater<int>> mp; int a, b; int num = 0; cin >> a; while(a--) { int s; double d; cin >> s >> d; mp[s] += d; } cin >> b; while(b--) { int s; double d; cin >> s >> d; mp[s] += d; } map<int, double, greater<int>> :: iterator it = mp.begin(); for(it = mp.begin(); it != mp.end(); it++) { if(it->second != 0) { num++; } } cout << num; // map<int, double, greater<int>> :: iterator it = mp.begin(); for(it = mp.begin(); it != mp.end(); it++) { if(it->second != 0) { printf(" %d %.1f", it->first, it->second); } } cout << endl; }
原文链接: https://www.cnblogs.com/lightac/p/12957602.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;
也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/350745
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!