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

2895的输入用JAVA到底应该怎么写?我这个是不行的。

Posted by daryl at 2006-07-25 13:43:15
import java.util.Scanner;
 
 public class Main {
 	
 	 public static int deal(char s) {
 	 	int tt = 0;
 		switch(s) {
 		case ' ': tt = 1;break;
		case 'A':tt = 21; break;
		case 'B': tt = 22; break;
		case 'C': tt = 23; break;
		case 'D': tt = 31; break;
		case 'E': tt = 32; break;
		case 'F': tt = 33; break;
		case 'G': tt = 41; break;
		case 'H': tt = 42; break;
		case 'I': tt = 43; break;
		case 'J': tt = 51; break;
		case 'K': tt = 52; break;
		case 'L': tt = 53; break;
		case 'M': tt = 61; break;
		case 'N': tt = 62; break;
		case 'O': tt = 63; break;
		case 'P': tt = 71; break;
		case 'Q': tt = 72; break;
		case 'R': tt = 73; break;
		case 'S': tt = 74; break;
		case 'T': tt = 81; break;
		case 'U': tt = 82; break;
		case 'V': tt = 83; break;
		case 'W': tt = 91; break;
		case 'X': tt = 92; break;
		case 'Y': tt = 93; break;
		case 'Z': tt = 94; break;
 		}
 		return tt;
 	}
 	
 	public static void main(String args[]) {
 		Scanner cin = new Scanner(System.in);
 		int time = 0;
 		int n = cin.nextInt();
 		while(n-- > 0) {
 			int a = cin.nextInt(),
 				b = cin.nextInt();
 			cin.skip("\n");
 			String str = cin.nextLine();
 			for(int j = 0; j < str.length(); j++) {
				if(j != str.length()-1)
					if(Main.deal(str.charAt(j)) / 10 != Main.deal(str.charAt(j + 1)) / 10)
						time += (Main.deal(str.charAt(j)) % 10) * a;
					else if(str.charAt(j) ==' ')
						time += (Main.deal(str.charAt(j)) % 10) * a;
					else
						time += Main.deal(str.charAt(j)) % 10 * a + b;
				else
					time += Main.deal(str.charAt(j)) % 10 * a;
 			}
 			System.out.println(time);
 			time = 0;
 		}
 	}
 }

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