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

java,Runtime ??? help please

Posted by javaWarrior at 2006-12-12 23:16:07 on Problem 3157
what is wrong??

//code
import java.io.*;
import java.util.*;

class Main{

static boolean validCodeC(char a[])
{

int i;
	
for(i=0;i<a.length;i++)
    if(Character.isUpperCase(a[i]))break;
    
    	
	
return (i==a.length);	

}

static boolean validCodeJ(char a[])
{

int i;
	
for(i=0;i<a.length;i++)
    if(Character.isUpperCase(a[i]))break;
    
    	
	
return (i<a.length);	

}
	
public static void main(String args[])throws IOException{
	
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader br = new BufferedReader(new FileReader("in.txt"));
StringBuffer s=new StringBuffer ();
ArrayList<Character>array;

StringTokenizer st;
String linea;
char codigo[];
int i,caso=1,tokens;	

//try{	

while((linea=br.readLine())!=null)
{

s.append("sample output #"+(caso++)+"\n");

st=new StringTokenizer((linea=br.readLine().trim()),"_");
tokens=0;
array=new ArrayList<Character>();

while(st.hasMoreTokens())
{
	st.nextToken();
	tokens++;
}

codigo=linea.toCharArray();

if(tokens==1){



if(validCodeJ(codigo))
{
for(i=0;i<codigo.length;i++)	
if(Character.isUpperCase(codigo[i]))
s.append("_"+Character.toLowerCase(codigo[i]));	
else s.append(codigo[i]);	
} else s.append(linea);
}

else
{

if(validCodeC(codigo))
{

for(i=0;i<codigo.length;i++)
 array.add(codigo[i]);
 
 for(i=0;i<array.size();i++)
   if(array.get(i)=='_'){
  	array.remove(i);
  	array.set(i,Character.toUpperCase(array.get(i)));
   }
  	
  	for(i=0;i<array.size();i++)
  	s.append(array.get(i));

}else s.append("Error!");



}

br.readLine();
s.append("\n\n");


	

}
System.out.println(s);
//}catch(IOException e){}
}
}


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