1002

注意点东西:

  1. 多项式相加系数为0的时候不能算作一项了
  2. 题目中输入输出的格式,最后一个空格,切记!
  3. 练习使用scanfpriintf这俩个函数!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
typedef struct polo
{
int exp;
float coe;
}polo;
int main()
{
int n1 , n2;
cin>>n1;
vector<polo> p1;
for(int i = 0 ; i < n1 ; ++i)
{
polo temp;
cin>>temp.exp;
cin>>temp.coe;
p1.push_back(temp);
}
cin>>n2;
vector<polo> p2;
for(int i = 0 ; i < n2 ; ++i)
{
polo temp;
cin>>temp.exp;
cin>>temp.coe;
p2.push_back(temp);
}
//vector<polo>::iterator end = p2.end();
vector<polo>::iterator del;
for(vector<polo>::iterator it = p2.begin() ; it != p2.end() ; ++it)
{
for(vector<polo>::iterator iter = p1.begin() ; iter != p1.end() ; ++iter)
{
if((*it).exp == (*iter).exp)
{
(*it).coe += (*iter).coe;
}
}
}
bool flag = false;
for(vector<polo>::iterator it = p1.begin() ; it != p1.end() ; ++it)
{
for(vector<polo>::iterator iter = p2.begin() ; iter != p2.end() ; ++iter)
{
if((*it).exp == (*iter).exp)
{
flag = true;
break;
}
flag = false;
}
if(!flag)
p2.push_back((*it));
}
//del 0
for( vector<polo>::iterator it = p2.begin() ; it != p2.end() ; )
{
if((*it).coe)
++it;
else
it = p2.erase(it);
}
// p1.~vector();
//output
printf("%d" , p2.size());
// cout<<p2.size()<<" ";
for(vector<polo>::iterator it = p2.begin() ; it != p2.end(); ++it)
{
// cout<<(*it).exp<<" "<<(*it).coe<<" ";
printf(" %d %.1lf",(*it).exp , (*it).coe);
}
printf("\n");
// cout<<endl;
return 0;
}

热评文章