Ozzy surfing around
taking notes about technology and daily things
Wednesday, January 30, 2013
tekrarlı harfleri sıkıştırma sorusu
soru
"aaaaaaabbbbbbbcccccddddaaaa" gibi bi string gelince "a7b7c5d4a4" şeklinde çıktı üretecek kodu yazınız.
cevap
public class denemeTest { public static void main(String[] args) { String deneme = "aaaaaaabbbbbbbcccccddddaaaa"; int i = 0; char denemes[] = deneme.toCharArray(); String cikti = ""; char bionceki = '\0'; for (int j = 0; j < denemes.length; j++) { char t = denemes[j]; if (j == 0) { bionceki = t; } if (bionceki == t) i++; else { cikti += bionceki + "" + i; i = 1; bionceki = t; } if (j == denemes.length - 1) { cikti += bionceki + "" + i; } } System.out.println(cikti); } }
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
speed test hyperoptic
Postgresql group by day, week and month examples
at the end of any product there will be a reporting interfaces for counts. let say you build a advertisement site which gives people to publ...
mounjaro diary day 1
I took the first jab in August 15 around 10:30 in the morning. no pain or nausea or dry mouth, I have been intermittent fasting since 2017 ...
UK court system
important for life in the uk test
No comments:
Post a Comment