how to seperate input string? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to seperate input string?

example input 1110001111 process count[1]=3 count[2]=3 count[3]=4 find which number that have the longest string which is 1 find the biggest count which is count[3] output 1 4 other example input 01001 process count[1]=1 count[2]=1 count[3]=2 count[4]=1 find which number that have the longest string which is 0 find the biggest count which is count[3] output 0 2

9th Nov 2018, 3:45 PM
Yoaraci
Yoaraci - avatar
3 Answers
+ 14
1)take the input as String 2)run the loop on that String & making a variable i=0 & counter variable a=1 ... start from i=0 to (length of word-2) & match i to i+1 index of characters of that word 3)when it matches increase value of a++ , when it doesn't matches make value of a=1 again . //coding I leave to you , simple logic I gave , give it a try in your favourite language .
9th Nov 2018, 4:22 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 2
Smells like homework... In C-like languages: int ii, ccnt, mcnt; char cch, mch; cch = arr[0]; mch = arr[0]; ii = 0; ccnt = 1; mcnt = 1; while (ii < arr_size) { if (arr[ii] != cch) { if (ccnt > mcnt) { mcnt = ccnt; mch = cch; ccnt = 1; cch = arr[ii]; } } ii++; ccnt++; } ^Along those lines (probably a typo or bug, did it on a phone to illustrate the concept): You iterate through the array, check for not-matches. If !match, check if current count is greater than max count, and if so, set the new max count and max char. Finally, reset the current count and continue.
9th Nov 2018, 4:21 PM
non
+ 1
Read all consecutive similar char (1 or 0) while to different char or end of input... For every one of this "block" check if its larger than last "block" processed, if its set the count of this block and symbol in apposite vars
9th Nov 2018, 4:07 PM
KrOW
KrOW - avatar