Блог пользователя eipie

Автор eipie, 14 лет назад, По-английски

Can someone help me find the java version specific bug or whatever here? Or the problem with my code Thanks!

Here is my code for the Petr# problem (113B - Petr#)

import java.util.*;
public class B {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String input = sc.next();
		String start = sc.next();
		String finish = sc.next();
		
		ArrayList<Integer> s = new ArrayList<Integer>();
		ArrayList<Integer> e = new ArrayList<Integer>();
		for (int i=0; i<input.length(); i++) {
			if (startsWith(input,start,i)) {
				s.add(i);
			}
			if (startsWith(input,finish,i)) {
				e.add(i);
			}
		}
		
		if (s.isEmpty() || e.isEmpty()) {
			System.out.println(0);
			return;
		}
				
		if (start.equals(finish)) {
			System.out.println(s.size());
			return;
		}
		
		HashSet<Integer> ans = new HashSet<Integer>();
		for (int i=0; i<s.size(); i++) {
			for (int j=0; j<e.size(); j++) {
				int x = e.get(j)-s.get(i);
				if (x<0)
					continue;
				ans.add(x);	
			}
		}
		System.out.println(ans.size());
	}
	
	private static boolean startsWith(String str, String search, int start) {
		if (str.length()-start < search.length())
			return false;		
		for (int i=0; i<search.length(); i++)
			if (str.charAt(start+i) != search.charAt(i))
				return false;
		return true;
	}
}

The input in question is: (the first word is split into two lines please make it ONE word)

adsflkdsjfmbvcxnvaeshjadskfnxvbrusighjdzbnxmgaldfbhzxnvbxcmvgaslugkzxcnbvxcnbvaselugtnbvzncblasjdfgnvbxzfalsdjgfadsgvbxcnvsayurqejhkdjzbvnzcgbgaskehgfmnbvmcvgasdgfnmbcvzmcvgadjtgaweuvxzcbvnxzcbfkahsgfbvznvbxzckugadjfasbvnzxcbvkdsjghdfskjbvxzmnbfalsefgsadhjvbznvbzxkngfsadkhfbxcvznbvkaedgfabvzncxvbzxckmbasdjgfbvnbzmvbzljrgfsahjvbxcnvbasdhfgjdsgvbxcnbasldgfsdujfdsjvbxmvbasdkhgfasdjfbasdnfbnvbxckvbadsuilfhadsjfbzvxcnbcxfgadujgadsjbvnbzvrjlghdsjhvnxncbvlsadjhadjshfasdkljfgfbdghfjbjfiadjvcnvsdjfbdvbjdshfkjehfldsakjhfjsadkhfksadljhfjsadklhfdsjakhfiewuyriubvznbxcvncbvzxuwqejnxcffeivbdqwetgrfvxcjmshbdfkjhwqrerfhsdjkvhbjwegfbxcdfjshnvhjdvhbfjsfdhbvdsajffvdhsabjfhvbeuofyrvboewufsadjhfvasdjhfvbsadlfvhsadljhfvbsadlvfsad

lkvfhsadljfvbhasdlfvbewvbwyufvbsaduyfvbsadjvhzlbvzxjchbvdufhdasjvfbhyeuwvbfuadhvbjsadvbfasbdhvfaoiuryweqiuyruqoweiyrsdfbhvdsjfhabsldfbvejhdsaiufyewiuqryqweiouvyrbwqeiubvriuwqeyvbbajsdhfvasdkfasdljkbfvhhajlsdhfvbcxzgahsjdkchnbxnuigeahfgdshfgdaskhfgsadkhfgadshfgdsahfgdaskhsadkfhgsadkhfgsadfkhdgsfkgdsakhfgdaskhfgasdkfgasdhfgdsafhadsgfksagfhkdsagfksadhfgbzncvbxnzcvbdlsjfhdsajflgwehjgtrdznbvcxmxcvblasdjhfaljsdkfhalsdkjfhasdkljfhalsdkjfhiewuytololonobodywillseethatdsjkfjaljxcmvxcbghfdjghdfjkhgdfjlsghfsdljhsdflghdfsjghfsdjlbcxnvnmcxzmnvxzcvbzxcmvbzxmcvbzxcnvbdsuagtywequityudhgjdkshgjklsdhgjfdkhgjlfsdkghlsdkfghdjfhgfdjghjkasdfhldsakjhfasjdklfhxcvnzbxcvnzbcxmvzcxhdsafjlsadjfhsadljhfieurytoueqytuihdfgkhsdflkjhvtyuweturetyurweotpqoewtguregdjkgbcxzmvbczvmzbxcnvzxsdahfuleyuyqetuiy
ad
iy
  • Проголосовать: нравится
  • +6
  • Проголосовать: не нравится

»
14 лет назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится

"Substrings are different if and only if their contents aren't equal, their positions of occurence don't matter." You are comparing length of this substrings. Use hachcodes.