www.www.zaachi.com » Blog/Algoritmy » Logické cvičení » Komentáře
#
Jan Kostelnik
(16.09.2009 19:16:08) Reagovat
Tady prikladam reseni v Jave :-]
String strNum = "1";
String testing;
String testing_next;
String result;
int count;
System.out.println(strNum);
for (int i = 0; i < 5; i++) {
result = "";
count = 1;
testing = strNum.substring(0, 1);
for (int j = 1; j < strNum.length(); j++) {
testing_next = strNum.substring(j, j + 1);
if (testing.equals(testing_next)) {
count++;
} else {
result += count + testing;
testing = new String(testing_next);
count = 1;
}
}
if (count > 1) {
result += count + testing;
} else {
result += String.valueOf(1) + testing;
}
strNum = new String(result);
System.out.println(strNum);
}
#
já
(01.09.2008 13:08:48) Reagovat
Tak tenhle humus znam se stredni skoly, takze vyreseno za par sekund (stacilo si jen vzpomenout). Popravde, nepredpokladal jsem, ze na to jeste nekdy natrefim :)