【ACM】P1000、P10001、P1002、P1003代码演示

(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): 205290


Problem Description

Calculate A + B.//计算A+B


Input  //输入
Each line will contain two integers A and B. Process to end of file.


Output
For each case, output A + B in one line.


Sample Input

1 1



Sample Output

2



Author
HDOJ
 *@author @qq.com">lxd
 *@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);
        }
    }
}

运行结果:

【ACM】P1000、P10001、P1002、P1003代码演示_第1张图片

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): 118540


Problem Description
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).

In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.(求解1+....+n的和)


Input
The input will consist of a series of integers n, one integer per line.


Output
For 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 Input

1
100



Sample Output

1

5050
 *@author "[email protected]">lxd
 *@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();
        }
    }
}

运行结果:

【ACM】P1000、P10001、P1002、P1003代码演示_第2张图片

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): 69087


Problem Description
I 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.


Output
For 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 Input

2
1 2
112233445566778899 998877665544332211



Sample Output

Case 1:
1 + 2 = 3

Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
 *@author "[email protected]">lxd
 *@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;inew 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();
            }
        }
    }
}

运行结果:

【ACM】P1000、P10001、P1002、P1003代码演示_第3张图片

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): 57233


Problem 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.


Input
The 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).


Output
For 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 Input

2
5 6 -1 5 4 -7
7 0 6 -1 1 -6 7 -5



Sample Output

Case 1:
14 1 4

Case 2:
7 1 6



 *@author "[email protected]">lxd
 *@version 1.0 2017-4-26 下午3:02:59
 *@fileName P1003.java
 */

代码演示:

你可能感兴趣的:(----,----②ACM,❼ACM/算法)