首页 > 代码库 > 算法之路——POJ刷题(Java,持续更新中)

算法之路——POJ刷题(Java,持续更新中)

先拿一些水题来练手了

1.POJ1000

import java.util.Scanner;/** * Created by mxcsky on 2015/1/25. */public class POJ1000 {    public static void main(String[] args){        Scanner in = new Scanner(System.in);        int a = in.nextInt();        int b = in.nextInt();        System.out.println(a + b);    }}

2.POJ1003

import java.util.Scanner;/** * Created by mxcsky on 2015/1/25. */public class POJ1003 {    public static void main(String[] args){        Scanner in = new Scanner(System.in);        while(true) {            double m = in.nextDouble();            double sum = 0.0;            int i = 1;            if (m < 0.00001) {                System.exit(0);            }            if (m <= 0.5) {                System.out.println("1 card(s)");            } else {                while (sum < m) {                    i++;                    sum = sum + 1.0 / i;                }                System.out.println((i - 1) + " card(s)");            }        }    }}

3.POJ1004

import java.util.Scanner;/** * Created by mxcsky on 2015/1/25. */public class POJ1004 {    public static void main(String[] args){        Scanner in = new Scanner(System.in);        double sum = 0.0;        for (int i = 0; i < 12; i++){            sum = sum + in.nextDouble();        }        System.out.printf("$%.2f", sum/12);    }}

 

算法之路——POJ刷题(Java,持续更新中)