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 - why wrong answer, please help i dont know what to do

Posted by javaWarrior at 2007-04-05 06:27:14 on Problem 3055
this is my code:

import java.io.*;
import java.util.*;

class Main {

static boolean evalRangos(char a,int i)
{

boolean bol=false;


switch(i)
{
	
case 1:

if(a>'0' &&  a<='9')
bol=true;
 
break;

case 2:

if(a>='0' &&  a<='9')
bol=true;

break;	

}

return bol;	
}


static boolean friends(char x[], char y[])
{
	
int i,j;

 for(i=0;i<x.length;i++){
 	
 for(j=0;j<y.length;j++)
      if(x[i]==y[j])
      break;	
 
 if(j==y.length)break;
 	
 }
  
  return (i==x.length);
 
}

static boolean almostFriends(char x[], char y[])
{

int i;
boolean bol;


for(i=0;i<x.length-1;i++){

StringBuffer xcopy=new StringBuffer();
xcopy.append(x);

 	
xcopy.setCharAt(i,(char)(x[i]-(char)1));
xcopy.setCharAt(i+1,(char)(x[i+1]+(char)1));

if(evalRangos((char)(x[i]-(char)1),1) && evalRangos((char)(x[i+1]+(char)1),2))
if(friends(xcopy.toString().toCharArray(),y))break;

xcopy.setCharAt(i,(char)(x[i]+(char)1));
xcopy.setCharAt(i+1,(char)(x[i+1]-(char)1));	

if(evalRangos((char)(x[i]+(char)1),1) && evalRangos((char)(x[i+1]-(char)1),2))
if(friends(xcopy.toString().toCharArray(),y))break;

}

bol=(i<x.length-1)?true:false;

if(!bol){

for(i=0;i<y.length-1;i++){

StringBuffer ycopy=new StringBuffer();
ycopy.append(y);

ycopy.setCharAt(i,(char)(y[i]-(char)1));
ycopy.setCharAt(i+1,(char)(y[i+1]+(char)1));

if(evalRangos((char)(y[i]-(char)1),1) && evalRangos((char)(y[i+1]+(char)1),2))
if(friends(x,ycopy.toString().toCharArray()))break;

ycopy.setCharAt(i,(char)(y[i]+(char)1));
ycopy.setCharAt(i+1,(char)(y[i+1]-(char)1));	

if(evalRangos((char)(y[i]+(char)1),1) && evalRangos((char)(y[i+1]-(char)1),2))
if(friends(x,ycopy.toString().toCharArray()))break;

}
bol=(i<y.length-1)?true:false;
}

return bol;

}

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();
	StringTokenizer st;	
		
	int t=new Integer(br.readLine());
	
	while(t-->0)
	{
	
	st=new StringTokenizer(br.readLine());
	
	char x[]=st.nextToken().toCharArray();
	char y[]=st.nextToken().toCharArray();
	
	boolean b;
		
	if(x.length<y.length)
	 b=friends(x,y);
	  else b=friends(y,x);
	
	if(b)s.append("friends\n");
	
	else{
	
	boolean bol;
	
	if(x.length<y.length)
	bol=almostFriends(x,y);
	 else 
		bol=almostFriends(y,x);
	
	if(bol)s.append("almost friends\n");
	 else s.append("nothing\n");	
		
	}
	}
	System.out.println(s);
	}

}	
		

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