AC

我是小学生  •  12天前


include <bits/stdc++.h>

using namespace std; string s;

int main() {

int k1,k2,t,c;
map<int,int> a;
cin>>k1>>k2;
while(k1--) {
	cin>>t>>c;
	if(a.find(c)==a.end()) {
		a[c]=0;
	}
	a[c]+=t;
}
while(k2--) {
	cin>>t>>c;
	if(a.find(c)==a.end()) {
		a[c]=0;
	}
	a[c]+=t;
}
for(auto it=a.begin(); it!=a.end(); it++) {
	if((*it).second!=0) {
		s+=to_string((*it).second)+"x^"+to_string((*it).first)+"+";
	}

}
s.erase(s.size()-1);
cout<<s;
return 0;

}


评论:

请先登录,才能进行评论