1001. A+B Format (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).

Input

Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.

Output

For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.

Sample Input

-1000000 9

Sample Output

-999,991

我的代码:
 package _1001;

 import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Scanner; public class Main { public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int a=sc.nextInt();
int b=sc.nextInt();
int ans=a-b;
NumberFormat format=new DecimalFormat("#,###,###");
String str=new String();
str=format.format(ans);
System.out.println(str);
}
}
}

1002. A+B for Polynomials (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

Input

Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1 N2 aN2 ... NK aNK, 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 1 <= K <= 10,0 <= NK < ... < N2 < N1 <=1000.

Output

For each test case you should output the sum of A and B 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

2 1 2.4 0 3.2
2 2 1.5 1 0.5

Sample Output

3 2 1.5 1 2.9 0 3.2
 package _1002;

 import java.util.Scanner;

 public class Main {

     public static void main(String[] args) {

         int n;
double[] a=new double[10];
double[] b=new double[10];
double[] ans=new double[10];
int i;
int max=0; //第一行
Scanner scan=new Scanner(System.in);
n=scan.nextInt();
for(i=0;i<n;i++){
int index=scan.nextInt();
a[index]=scan.nextDouble();
} //第二行
scan=new Scanner(System.in);
n=scan.nextInt();
for(i=0;i<n;i++){
int index=scan.nextInt();
b[index]=scan.nextDouble();
} for(i=0;i<10;i++){
ans[i]=b[i]+a[i];
}
for(i=9;i>=0;i--){
if(ans[i]!=0){
max=i+1;
break;
}
}
System.out.print(max);
for(i=max-1;i>=0;i--){//保证一位小数规格化输出
System.out.format(" %d %.1f", i,ans[i]);
}
System.out.println();
} }

PAT刷题 (Java语言)的更多相关文章

  1. 算法笔记_216:第六届蓝桥杯软件类校赛部分真题(Java语言C组)

    目录 1 题目一 2 题目二 3 题目三 4 题目四 5 题目五 前言:以下代码仅供参考,若有错误欢迎指正哦~ 1 题目一 二项式的系数规律,我国数学家很早就发现了. 如[图1.png],我国南宋数学 ...

  2. 算法笔记_206:第五届蓝桥杯软件类决赛真题(Java语言A组)

    目录 1 海盗分金币 2 六角幻方 3 格子放鸡蛋 4 排列序数 5 幂一矩阵 6 供水设施    前言:以下代码仅供参考,若有错误欢迎指正哦~ 1 海盗分金币 有5个海盗,相约进行一次帆船比赛. 比 ...

  3. 算法笔记_208:第六届蓝桥杯软件类决赛真题(Java语言A组)

    目录 1 胡同门牌号 2 四阶幻方 3 显示二叉树 4 穿越雷区 5 切开字符串 6 铺瓷砖   前言:以下代码仅供参考,若有错误欢迎指正哦~ 1 胡同门牌号 标题:胡同门牌号 小明家住在一条胡同里. ...

  4. 算法笔记_210:第六届蓝桥杯软件类决赛真题(Java语言C组)

    目录 1 机器人数目 2 生成回文数 3 空心菱形 4 奇怪的数列 5 密文搜索 6 居民集会 前言:以下代码仅供参考,若有错误欢迎指正哦~ 1 机器人数目 标题:机器人数目 少年宫新近邮购了小机器人 ...

  5. 算法笔记_215:第六届蓝桥杯软件类校赛部分真题(Java语言B组)

    目录 1 题目一 2 题目二 3 题目三 前言:以下代码仅供参考,若有错误欢迎指正哦~ 1 题目一 java中提供了对正则表达式的支持. 有的时候,恰当地使用正则,可以让我们的工作事半功倍! 如下代码 ...

  6. 算法笔记_214:第六届蓝桥杯软件类校赛真题(Java语言A组)

    目录 1 题目一 2 题目二 3 题目三 4 题目四 5 题目五 6 题目六 7 题目七 前言:以下代码仅供参考,若有错误欢迎指正哦~ 1 题目一 一个串的子串是指该串的一个连续的局部.如果不要求连续 ...

  7. 算法笔记_204:第四届蓝桥杯软件类决赛真题(Java语言C组)

    目录 1 好好学习 2 埃及分数 3 金蝉素数 4 横向打印二叉树 5 危险系数 6 公式求值   前言:以下代码仅供参考,若有错误欢迎指正哦~ 1 好好学习 汤姆跟爷爷来中国旅游.一天,他帮助中国的 ...

  8. 算法笔记_207:第五届蓝桥杯软件类决赛部分真题(Java语言C组)

    目录 1 数字拆分 2 稍大的串   前言:以下代码仅供参考,若有错误欢迎指正哦~ 1 数字拆分 正整数可以表示为若干正整数的累加和. 如,对于正整数n=6,可以分划为: 6 5+1 4+2 4+1+ ...

  9. 算法笔记_211:第七届蓝桥杯软件类决赛部分真题(Java语言A组)

    目录 1 阶乘位数 2 凑平方数 3 棋子换位 4 机器人塔 前言:以下代码仅供参考,若有错误欢迎指正哦~ 1 阶乘位数 阶乘位数 9的阶乘等于:362880 它的二进制表示为:10110001001 ...

随机推荐

  1. JSON数据格式:以及XML文件格式,YML文件格式,properties文件格式

    JSON数据格式:以及XML文件格式,YML文件格式,properties文件格式   数据格式: json数据格式:属于轻量级数据格式,是javascript的一种描述数据的格式.具有易于解析,语法 ...

  2. 怎样调节Eclipse中的字体大小?

    window->perference->appearance->colors and font->text font edit

  3. Visual Studio 技巧

    Visual Studio 技巧 1 常用设置 2 常用快捷键 2.1 系统默认快捷键 2.2 自定义快捷键 3 修复系统错误 1 常用设置 Text Editor -> All Languag ...

  4. 由一个空工程改为SpringBoot工程

    1.先创建一个空的工程,创建springboot 工程  必须继承spring-boot-stater-parent 2.导入依赖 <parent> <groupId>org. ...

  5. jQuery简易Ajax(六)

    一.jQuery中ajax的两种书写方式[一般采用第二种方式]1.$.ajax(url,[setting]); 2.$.ajax([setting]); setting参数说明:setting为一个对 ...

  6. QT之Qt之Q_PROPERTY宏理解

    在初学Qt的过程中,时不时地要通过F2快捷键来查看QT类的定义,发现类定义中有许多Q_PROPERTY的东西,比如最常用的QWidget的类定义: Qt中的Q_PROPERTY宏在Qt中是很常用的,那 ...

  7. RabbitMQ基本概念(二)-RabbitMQ消息队列架构与基本概念

    没错我还是没有讲怎么安装和写一个HelloWord,不过快了,这一章我们先了解下RabbitMQ的基本概念. RabbitMQ架构 说是架构其实更像是应用场景下的架构(自己画的有点丑,勿嫌弃) 从图中 ...

  8. DRF(django-rest_framework)框架

    drf执行流程,APIView,Request -继承APIView(继承自view),重写了dispatch方法 -dispatch方法:1 request对象,被重新封装了,成了新的request ...

  9. Laravel实现用户的注册、登录

    一.安装 Laravel(使用 Laravel5.5) 通过 Composer 创建项目 composer create-project --prefer-dist laravel/laravel s ...

  10. 【转】STM32利用FATFS读写数组

    因为存为TXT可以实现,但是读取TXT里边的数据总是不尽如人意,所以,最终存为bin文件了. 先摘几个观点: http://www.openedv.com/posts/list/36712.htm “ ...