五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

【Python】PAT 甲級 A1002:A+B for Polynomials

2021-02-10 21:52 作者:曉霧喵  | 我要投稿

題目內(nèi)容

This time, you are supposed to find?+?where??and??are two polynomials.

Input Specification:

Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:

where?K?is the number of nonzero terms in the polynomial,?Ni?and?aNi?(i=1,2,?,K) are the exponents and coefficients, respectively. It is given that?1K100NK<?<N2<N11000.

Output Specification:

For each test case you should output the sum of ?and ? in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate to 1 decimal place.

Sample Input:

Sample Output:

題目要點(diǎn)

本題 25 分,是比較簡單的模擬題。在輸入時,Python可以不用考慮給定的,直接用數(shù)組切片隔位取指數(shù)列表、系數(shù)列表,再用zip()構(gòu)造字典。

重點(diǎn)需要考慮的是如何將多項式的指數(shù)和對應(yīng)系數(shù)映射。C/C++可以用數(shù)組下標(biāo)作為指數(shù),數(shù)組浮點(diǎn)數(shù)值為對應(yīng)系數(shù)。這里Python使用字典比較方便,而且考慮到兩個多項式的指數(shù)項不一定相同,在求和時要指數(shù)項系數(shù)對應(yīng)相加,Python可以使用集合的求并集|運(yùn)算符實(shí)現(xiàn)。

注意,測試點(diǎn)6是非零系數(shù)項個數(shù),也就是為0的情況,這時候只輸出0。如果有多余空格會出現(xiàn)“格式錯誤”。

AC 源代碼


【Python】PAT 甲級 A1002:A+B for Polynomials的評論 (共 條)

分享到微博請遵守國家法律
福鼎市| 闽侯县| 建始县| 延庆县| 屯昌县| 扶余县| 象州县| 夹江县| 通州区| 鹿泉市| 青冈县| 灵丘县| 商南县| 阜康市| 台湾省| 汶川县| 黔西县| 枝江市| 宝坻区| 文昌市| 孟州市| 和顺县| 贵南县| 望都县| 开鲁县| 阿鲁科尔沁旗| 太原市| 温泉县| 正定县| 黔江区| 莫力| 新丰县| 临洮县| 吴堡县| 巴楚县| 永善县| 扶余县| 晋江市| 攀枝花市| 大庆市| 和平县|