Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

同1338 极其经典的算法

Posted by xuchang at 2011-03-15 15:41:35 on Problem 2247
import java.io.*;
import java.util.*;

public class Main {
	static int[] data = new int[5843];
	static {
		data[1] = 1;
		int c = 2, c2 = 1, c3 = 1, c5 = 1, c7 = 1;
		while (c < 5843) {
			data[c] = min(data[c2] * 2, data[c3] * 3, data[c5] * 5,
					data[c7] * 7);
			if (data[c] == data[c2] * 2)
				c2++;
			if (data[c] == data[c3] * 3)
				c3++;
			if (data[c] == data[c5] * 5)
				c5++;
			if (data[c] == data[c7] * 7)
				c7++;
			c++;
		}
	}

       private static int min(int i, int j, int k, int l) {
		return (i < j ? i : j) < (k < l ? k : l) ? (i < j ? i : j) : (k < l ? k
				: l);
	}

	public static void main(String args[]) throws Exception {
		Scanner cin = new Scanner(System.in);
		int i;
		String s;
		while ((i=cin.nextInt())!=0) {
			if(i%10==1&&i%100!=11)
				s=i+"st";
			else if(i%10==2&&i%100!=12)
				s=i+"nd";
			else if(i%10==3&&i%100!=13)
				s=i+"rd";
			else
				s=i+"th";
			System.out.println("The "+s+" humble number is "+data[i]+".");
		}

	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator