1001 A+B Format
-
如果一个数组被部分初始化,没有被初始化的元素会被自动设置为相应类型的0。
int arr[1024] = {0}; //this will make all ZERO
1002 A+B for Polynomials
-
坑:考虑系数和为零的情况要剔除;系数要保留一位小数;按N从大到小进行排序。
-
输出时保留小数:
printf("%.1f", vec[i].second);
-
较好的写法:
#include<iostream> #include<map> #include<iterator> using namespace std; map<int ,double>m; void solve() { int n; cin>>n; while(n--) { int x;double y; cin>>x>>y; m[x]+=y; if(m[x]==0)//如果系数为0,那么删除此数据项 m.erase(x); } } int main() { solve(); solve(); cout<<m.size(); for(auto it=m.rbegin();it!=m.rend();it++) printf(" %d %.1lf",it->first,it->second); return 0; }
1003 Emergency