听说这是超时,有没有过来人告诉我怎么办啊?我感觉我做的都是比较简单的题(1004,1005,1008),感觉也没有什么东西运行需要太多的时间,怎么就会超呢?
下面是代码.请高手帮我看一下.
import java.util.Scanner;public class Main1004 {
public static void main(String[] args) {
double total = 0.00d;
double ave = 0.00d;
for(int i=0; i<12; i++) {
Scanner sc = new Scanner(System.in);
double d = sc.nextDouble();
total += d;
}
ave = total/12;
System.out.println("$" + ave);
}
}import java.util.Scanner;
import java.util.regex.Pattern;public class Main1005 {
public static void main(String[] args) {
Scanner sca = new Scanner(System.in);
int times = sca.nextInt();
int[] years = new int[times];
for(int i=0; i<times; i++) {
Scanner cin = new Scanner(System.in);
double rad1 = cin.nextDouble();
double rad2 = cin.nextDouble();
years[i] = (int)((rad1 * rad1 + rad2 * rad2)*Math.PI)/2/50 + 1;

}

for(int i=0; i<times; i++) {
System.out.println("Property " + (i+1) + 
": This property will begin eroding in year " + years[i] +"."); }
System.out.println("END OF OUTPUT.");
}
}import java.util.Scanner;
import java.util.regex.Pattern;public class Main1008 {
public static void main(String[] args) {
int totalDays = 0;
int hYears = 0;
int yYears = 0;
int hMons = 0;
int yMons = 0;
int yData = 0;
int hDays = 0;
int yDays = 0;

Scanner cin = new Scanner(System.in);
int time = cin.nextInt();
String[] sHaab = new String[] { "pop", "no", "zip", "zotz", "tzec",
"xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac",
"kankin", "muan", "pax", "koyab", "cumhu", "uayet" };

String[] sTzo = new String[] { "imix", "ik", "akbal", "kan",
"chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen",
"eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"};
String[] strs = new String[3];
String[] finallDatas = new String[time];
Pattern p1 = Pattern.compile("\\.");
Pattern p2 = Pattern.compile("\\s"); for (int i = 0; i < time; i++) {
Scanner inPut = new Scanner(System.in); String str = p1.matcher(inPut.nextLine()).replaceAll("");
strs = p2.split(str); for (int j = 0; j < sHaab.length; j++) {
if(sHaab[j].equals(strs[1])) hMons = j+1;
}
hYears = Integer.parseInt(strs[2]);
hDays = Integer.parseInt(strs[0]) + 1;
totalDays = hYears * 365 + (hMons-1) * 20 + hDays;

yYears = totalDays/260;
yMons = (totalDays%260)/13;
yData = (totalDays%260)%13;
yDays = (totalDays%260)%20;
finallDatas[i] = yData + " " + sTzo[yDays - 1] + " " + yYears; 

}
System.out.println(time);
for(int i=0; i < finallDatas.length; i++) {
System.out.println(finallDatas[i]);
}
}
}