1002 A+B for Polynomials (25分)(模拟题)

题目链接

需要先了解

#if 0
#include<bits/stdc++.h>
using namespace std;
int main() {
	cout << "--------------1----------" << endl;

	//setw只对接下来输出的 有效
	cout << setw(3) << 1 << setw(3) << 10 << setw(3) << 100;
	cout << endl;
	cout << setw(3) << 1 << 10 << setw(3) << 100 << endl;

	cout <<"--------------2----------" << endl;

	//fixed/setprecision对之后都有效
	double a=9.235, b=6.5937;
	cout << a << fixed << setprecision(1) << " " << b << endl;
	cout << a << fixed << setprecision(1) << " " << b << endl;
	int num = 100;
	double num3 = 9.235325;
	cout << num << endl;
	cout << num3 << endl;

	cout << "--------------3----------" << endl;

	//解决方法,恢复默认状态,哎,setprecision fixed这俩哥们真难对付
	cout << num3 << endl;
	cout<<setprecision(6);
	cout << num3 << endl;
	cout.unsetf(ios::fixed);
	cout << num3 << endl;

	cout << "--------------4----------" << endl;

	//无所谓的一些尝试
	double f = 3.123456789;
	cout << f << endl;   
	cout << setprecision(2) << f << endl;  
	cout << fixed << f << endl;   
	cout << setprecision(2) << fixed << f << endl;  
	cout << fixed << setprecision(2) << f << endl;  

}
#endif

代码

#if 1
#include<string>
using namespace std;
#include <iostream>
#include <iomanip>
#include<map>
int a,id;
double temp;
map<int, double>deal;
void func() {
	cin >> a;
	for (int i = 0; i < a; i++) {
		cin >> id >> temp;
		deal[id] += temp;
	}
}
int main() {
	func();
	func();
	for (auto i = deal.begin(); i != deal.end(); i++) {
		if (i->second == 0)deal.erase(i);
	}
	cout << deal.size();
	if (deal.size() != 0) {
		for (auto i = deal.rbegin(); i != deal.rend(); i++) {			
			cout << " " << i->first <<fixed<<setprecision(1)<< " " << i->second;
		}
	}
	return 0;
}
#endif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值