【ACM】P1000、P10001、P1002、P1003代码演示
来源:互联网 发布:淘宝投诉卖假货怎么办 编辑:程序博客网 时间:2024/06/05 15:20
(p1000) 问题描述(A+B Problem):
/*** * A + B Problem(解决A+B简单问题)Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 658688 Accepted Submission(s): 205290Problem DescriptionCalculate A + B.//计算A+BInput //输入Each line will contain two integers A and B. Process to end of file.OutputFor each case, output A + B in one line.Sample Input1 1Sample Output2AuthorHDOJ *@author <a"283505495@qq.com">lxd</a> *@version 1.0 2017-4-26 下午1:53:07 *@fileName P1000.java */
代码演示:
package ac;import java.util.Scanner;public class P1000 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int a=sc.nextInt(); int b=sc.nextInt(); int sum=a+b; System.out.println(sum); } }}
运行结果:
p1001问题描述(Sum Problem):
/** * Sum Problem(求和问题)Time Limit: 1000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 470318 Accepted Submission(s): 118540Problem DescriptionHey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.(求解1+....+n的和)InputThe input will consist of a series of integers n, one integer per line.OutputFor each case, output SUM(n) in one line, followed by a blank line. 32位的整数 也许n的值特别大You may assume the result will be in the range of 32-bit signed integer.Sample Input1100Sample Output15050 *@author <a"283505495@qq.com">lxd</a> *@version 1.0 2017-4-26 下午2:09:34 *@fileName p1001.java */
代码演示:
package ac;import java.util.Scanner;public class p1001 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int n=sc.nextInt(); int sum=0; for(int i=1;i<=n;i++){ sum+=i; } System.out.println(sum); System.out.println(); } }}
运行结果:
p1002问题描述(A + B Problem II(A+B问题2 —–利用大数进行解决)):
/** * A + B Problem II(A+B问题2 -----利用大数进行解决)Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 356144 Accepted Submission(s): 69087Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.Input (情况个数T)The first line of the input contains an integer T(1<=T<=20) which means the number of test cases.(这两个A、B数可能非常大)Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, (比32位整数还要大)that means you should not process them by using 32-bit integer. (整数长度不要超过1000)You may assume the length of each integer will not exceed 1000.OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. he second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.Sample Input21 2112233445566778899 998877665544332211Sample OutputCase 1:1 + 2 = 3Case 2:112233445566778899 + 998877665544332211 = 1111111111111111110 *@author <a"283505495@qq.com">lxd</a> *@version 1.0 2017-4-26 下午2:16:06 *@fileName P1002.java */
代码演示:
package ac;import java.math.BigInteger;import java.util.Scanner;public class P1002 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); /** * 1、java.util.math中的BigInteger类,用来封装大数,可以对大数进行基本的操作。 */ int t=sc.nextInt(); for(int i=0;i<t;i++){ BigInteger a=new BigInteger(sc.next()); BigInteger b=new BigInteger(sc.next()); BigInteger sum=a.add(b); System.out.println("Case "+(i+1)+":"); /** * a、b、sum必须转换为toString */ System.out.println(a.toString()+" + "+b.toString()+" = "+sum.toString()); if(i!=t-1){ System.out.println(); } } }}
运行结果:
p1003问题描述(Max Sum(求一个无序序列的最大和)):
/** * Max Sum(求一个无序序列的最大和)Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 242414 Accepted Submission(s): 57233Problem Description给定一个序列值,计算出此序列的最大和Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. 最大和、起始位置、结束位置The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.Sample Input25 6 -1 5 4 -77 0 6 -1 1 -6 7 -5Sample OutputCase 1:14 1 4Case 2:7 1 6 *@author <a"283505495@qq.com">lxd</a> *@version 1.0 2017-4-26 下午3:02:59 *@fileName P1003.java */
代码演示:
0 0
- 【ACM】P1000、P10001、P1002、P1003代码演示
- P1002
- P1003
- 【ACM】P2011、P2012、P2013(*)、P2014代码演示
- acm hdu p1002 A + B Problem II
- 【ACM】P2000、P2001、P2002、P2003、P2004、P2005代码演示
- 【ACM】P2006、P2007、P2008、P2009、P2010代码演示
- 【ACM】P2015(*)、P2016、P2017、P2018(*)、P2019代码演示
- 【ACM】P2020、P2021、P2022、P2023、P2024代码演示
- 【ACM】P2025、P2026、P2027、P2028、P2029代码演示
- 【ACM】P2030、P2031、P2032、P2033、P2034代码演示
- 蓝桥杯 算法提高 P1003 要敲帅气的代码
- 代码演示
- HDU P1002
- TYVJ P1002
- 洛谷 P1003
- 魔法表情演示代码
- Ext 的代码演示
- 【LeetCode】 回溯系列
- 八皇后算法
- Problem F: 分数类的模板数组类
- 线段树
- Windows通过 iis创建FTP服务
- 【ACM】P1000、P10001、P1002、P1003代码演示
- BW 库存管理之processkey
- Comparable和Comparator
- 从此以后,江湖有了它的传说!
- u3d安卓打包
- bootstrap-paginator分页插件无格式
- 长链接转短链接
- 一. C&C++ 基础二
- A+B+C问题