Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我感觉我的代码还是比较美观的import java.util.*; public class Main_4 { static double P,I,U; static String arr;static int i; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //String z="="; // System.out.println((int)z.charAt(0)); Scanner sca=new Scanner(System.in); int k=0; int num=Integer.parseInt(sca.nextLine()); while(num>0){k++; num--; arr=sca.nextLine(); j1=false; j2=false; j3=false; for( i=0;i<arr.length();i++){ int t=arr.charAt(i); if(t==61){int p=arr.charAt(i-1); int xy=ju(p); cal(i+1, xy); } }System.out.println("Problem #"+k); //System.out.println(j1+" "+j2+" "+j3); if(j1&&j2){ System.out.println("U="+String.format("%.2f", P/I)+"V"); }else if(j1&&j3){ System.out.println("I="+String.format("%.2f",P/U)+"A"); }else if(j2&&j3){ System.out.println("P="+String.format("%.2f",U*I)+"W"); }System.out.println(); } }static boolean j1,j2,j3; static int ju(int a){ if(a==80){ j1=true; return 1; }else if(a==73){ j2=true; return 2; }else if(a==85){ j3=true; return 3; } return -1; }static void cal(int start,int t){ int temp=start; if(t==1){ int z=arr.charAt(start); while(z!=87){ start++; z=arr.charAt(start); }int u=arr.charAt(start-1); double ds=pd(u); if(ds!=-1){ P=Double.parseDouble(arr.substring(temp, start-1))*ds; }else{ P=Double.parseDouble(arr.substring(temp, start)); }i=start; }else if(t==2){ int z=arr.charAt(start); while(z!=65){ start++; z=arr.charAt(start); }int u=arr.charAt(start-1); double ds=pd(u); if(ds!=-1){I=Double.parseDouble(arr.substring(temp, start-1))*ds; }else{ I=Double.parseDouble(arr.substring(temp, start)); }i=start; }else if(t==3){ int z=arr.charAt(start); while(z!=86){ start++; z=arr.charAt(start); } int u=arr.charAt(start-1); double ds=pd(u); if(ds!=-1){U=Double.parseDouble(arr.substring(temp, start-1))*ds; }else{ U=Double.parseDouble(arr.substring(temp, start)); }i=start; } }static double pd(int t){ if(t==109){ return 0.001; } if(t==107){ return 1000; } if(t==77){ return 1000000; } return -1; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator