| ||||||||||
| 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 | |||||||||
请那位牛人帮忙看看啊,不知道哪里错了,所有的测试数据都调了,一直报Runtime error,帮个忙啊 ,谢谢拉代码是这样的:
//1207 实在是不知道哪里错了啊....
import java.util.*;
import java.io.*;
public class Main {
int timeCount(int source){
int count=0;
while(source!=1){
if(source%2==1) {
source=source*3+1;
count++;
}else{
source=source/2;
count++;
}
}
return (count+1);
}
int timeMax(int i,int j){
int timemax=0;int low=i;int high=j;
if(i>j){low=j;high=i;}
for(int k=low;k<=high;k++)
if(timeCount(k)>timemax) timemax=timeCount(k);
return timemax;
}
public static void main(String[] args) throws IOException{
Main m=new Main();
Vector vec=new Vector();
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
String line=stdin.readLine();
StringTokenizer st=new StringTokenizer(line);
while(st.countTokens()==2){
int begin=Integer.parseInt(st.nextToken());
int end=Integer.parseInt(st.nextToken());
int temp=m.timeMax(begin, end);
vec.addElement(begin+" "+end+" "+temp);
line=stdin.readLine();
st=new StringTokenizer(line);
}
for(int i=0;i<vec.size();i++){
System.out.println(vec.elementAt(i));
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator