开始学习ACM,刷杭电OJ

来源:互联网 发布:电脑数据库在哪里 编辑:程序博客网 时间:2024/05/30 04:30

java写acm类名必须为Main
第1000题

import java.util.Scanner;public class Main {    /**     * @param args     */    public static void main(String[] args) {        // TODO Auto-generated method stub        Scanner s = new Scanner(System.in);        while (s.hasNextInt()) {            int a = s.nextInt();            int b = s.nextInt();            System.out.println(a + b);        }    }}

第1001题

import java.util.Scanner;public class Main {    /**     * @param args     */    public static void main(String[] args) {        // TODO Auto-generated method stub        Scanner s = new Scanner(System.in);        while (s.hasNextInt()) {            int n = s.nextInt();            int sum = 0;            for (int i = 0; i <= n; i++) {                sum = sum + i;            }            System.out.println(sum);            System.out.println();        }    }}

第1002题

import java.math.BigInteger;import java.util.Scanner;public class Main {    public static void main(String[] args) {        Scanner s = new Scanner(System.in);        int t = s.nextInt();        for (int i = 0; i < t; i++) {            BigInteger a = s.nextBigInteger();            BigInteger b = s.nextBigInteger();            System.out.println("Case" + " " + +(i + 1) + ":");            System.out.println(a + " + " + b + " = " + a.add(b));            if (i != t - 1) {                System.out.println();            }        }    }}
0 0
原创粉丝点击