AC代码

转载自https://www.cnblogs.com/zjutJY/p/9413766.html

  1. #include <stdio.h>
  2. #include<string.h>
  3. //输入:两行数据,每行表示一个多项式:第一个数字表示非零项的数目,
  4. //后面每两个数表示一项,分别表示幂次和系数。
  5. //输出:两个多项式的和,格式与输入一样
  6. int main(){
  7. const int MAX_N=1111;
  8. double a=0.0;
  9. int k,n=0,count=0,i;//k:输入的非零项数,n:幂次,a:系数,count:和的非零项数
  10. double p[1111]={0};//声明时使用{0}初始化为全0
  11. //double p[MAX_N];
  12. //memset(p,0,MAX_N);//使用memset方法,注意要加string.h头文件
  13. // for(i=MAX_N-1;i>=0;i--){
  14. // printf("%.1f",p[i]);
  15. // }
  16. //输入第一行数据
  17. scanf("%d",&k);
  18. for(i=0;i<k;i++){
  19. scanf("%d %lf",&n,&a);
  20. p[n]+=a;
  21. }
  22. //输入第二行数据
  23. scanf("%d",&k);
  24. for(i=0;i<k;i++){
  25. scanf("%d %lf",&n,&a);
  26. p[n]+=a;
  27. }
  28. for(i=0;i<MAX_N;i++){
  29. if(p[i]){
  30. count++;
  31. }
  32. }
  33. printf("%d",count);
  34. for(i=MAX_N-1;i>=0;i--){
  35. if(p[i]){
  36. printf(" ");
  37. printf("%d %.1f",i,p[i]);
  38. }
  39. }
  40. return 0;
  41. }

自己写的, 一个都没有通过

  1. #include <cstdio>
  2. #include <algorithm>
  3. #define N 1010
  4. using namespace std;
  5. int main() {
  6. #ifdef ONLINE_JUDGE
  7. #else
  8. freopen("1.txt", "r", stdin);
  9. #endif // ONLINE_JUDGE
  10. double num[N] = {0.0};
  11. int big = 0, t = 0;
  12. for(int i = 0; i < 2; i++) {
  13. int n;
  14. scanf("%d", &n);
  15. for(int i = 0; i < n; i++) {
  16. int a;
  17. double b;
  18. scanf("%d %1f", &a, &b);
  19. num[a] += b;
  20. //if(big < a) swap(big, a);
  21. //t++;
  22. }
  23. }
  24. for(int i = 0; i < N; i++) {
  25. if(num[i] != 0) {
  26. t++;
  27. }
  28. }
  29. printf("%d", t);
  30. for(int i = N; i >= 0; i--) {
  31. if(num[i] != 0.0){
  32. printf(" %d %.1f", i, num[i]);
  33. }
  34. }
  35. return 0;
  36. }

PAT A1002 A+B for Polynomials(25)的更多相关文章

  1. PAT 1002. A+B for Polynomials (25) 简单模拟

    1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...

  2. PAT甲 1009. Product of Polynomials (25) 2016-09-09 23:02 96人阅读 评论(0) 收藏

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  3. PAT 甲级 1009 Product of Polynomials (25)(25 分)(坑比较多,a可能很大,a也有可能是负数,回头再看看)

    1009 Product of Polynomials (25)(25 分) This time, you are supposed to find A*B where A and B are two ...

  4. A1002 A+B for Polynomials (25)(25 分)

    1002 A+B for Polynomials (25)(25 分) This time, you are supposed to find A+B where A and B are two po ...

  5. pat 甲级 1009. Product of Polynomials (25)

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  6. 【PAT】1009. Product of Polynomials (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...

  7. PAT 1002. A+B for Polynomials (25)

    This time, you are supposed to find A+B where A and B are two polynomials. Input Each input file con ...

  8. PAT Advanced 1009 Product of Polynomials (25 分)(vector删除元素用的是erase)

    This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...

  9. PAT 1002 A+B for Polynomials (25分)

    题目 This time, you are supposed to find A+B where A and B are two polynomials. Input Specification: E ...

随机推荐

  1. delphi将两个Strlist合并,求交集 (保留相同的)

    Function StrList_Join(StrListA,StrListB:String):String; //将两个Strlist合并,求交集 (保留相同的) var SListA,SListB ...

  2. layer提示带文字

    直接撸代码: //加载层-风格4 layer.msg('加载中', { icon: 16 ,shade: 0.01 });

  3. Linux系统是否被植入木马的排查流程梳理

    在日常繁琐的运维工作中,对linux服务器进行安全检查是一个非常重要的环节.今天,分享一下如何检查linux系统是否遭受了入侵? 一.是否入侵检查 1)检查系统日志 1 2 检查系统错误登陆日志,统计 ...

  4. 使用pyinstaller 打包python程序

    1.打开PyCharm的Terminal,使用命令pip install pyinstaller安装pyinstaller 2.打包命令:pyinstaller --console --onefile ...

  5. Hibernate3核心API使用

    public static void main(String[] args) throws Exception{ // 1. 加载默认的hibernate.cfg.xml的配置文件 Configura ...

  6. 【转】MAC 配置ssh免密登录

    配了挺多次免密登录,老是忘了,备份一下 转载自知乎,如侵删.https://zhuanlan.zhihu.com/p/32279976 -------------------------------- ...

  7. 基于Scrapy框架的增量式爬虫

    概述 概念:监测 核心技术:去重 基于 redis 的一个去重 适合使用增量式的网站: 基于深度爬取的 对爬取过的页面url进行一个记录(记录表) 基于非深度爬取的 记录表:爬取过的数据对应的数据指纹 ...

  8. Swift3.0项目学习: 创建撰写按钮

    import UIKit class PSMainViewController: UITabBarController { override func viewDidLoad() { super.vi ...

  9. Java泛型(6):extends和super关键字

    (1) <T extends A> 因为擦除移除了类型信息,而无界的泛型参数调用的方法只等同于Object.但是我们可以限定这个泛型参数为某个类型A的子集,这样泛型参数声明的引用就可以用类 ...

  10. 生命周期中mounted和created的区别。

    一.什么是生命周期? 用通俗的语言来说,就是Vue中实例或者组件从创建到消灭中间经过的一系列过程.虽然不太严谨,但是也基本上可以理解. 通过一系列实践,现在把所有遇到的问题整理一遍,今天记录一下cre ...