pat a1002

来源:互联网 发布:数据库第六版中文答案7 编辑:程序博客网 时间:2024/06/07 20:30
水题,注意格式控制就就可以了,以及变量类型是否正确
#include <cstdio>#include <iostream>using namespace std;int main(){//freopen("1.txt","r",stdin);double a[1010]={0};int n,m;cin>>n;for(int i=0;i<n;i++){int temp;cin>>temp;cin>>a[temp];}cin>>m;for (int i=0;i<m;i++){int temp;double cotemp;cin>>temp>>cotemp;if(a[temp]==0) n++;a[temp]+=cotemp;if(a[temp]==0) n--;}cout<<n;for (int i=1000;i>=0;i--){if(a[i]!=0) printf(" %d %.1f",i,a[i]);}cout<<endl;return 0;}

0 0