+ 9

⛷ Challenge ⛷ Find the largest string from the given string...

Suppose user Enters a string "Goodcommunication" You have to count no of letters in string from starts and whenever a repeated character ouucers from previous string cut the previous string and start counting new string from current letter this explanation will little bit confuse you I will show you example check out 1st comment for example... if you need more explanation mentioned in cmnts https://code.sololearn.com/cn4zPRALAtF1/?ref=app

3rd Nov 2017, 5:14 AM
Pranit Gandhi
Pranit Gandhi - avatar
10 Antworten
+ 8
Thanks for the challenge. Here's my answer : https://code.sololearn.com/cb6C4xnFiSZH/?ref=app
3rd Nov 2017, 7:53 PM
LukArToDo
LukArToDo - avatar
+ 4
ex->String=GoodCommunication string 1=Go(2) string 2=odC(3) string 3=om(2) string 4=municat(7) string 5=ion(3) largest string is string4.
3rd Nov 2017, 5:25 AM
Pranit Gandhi
Pranit Gandhi - avatar
+ 3
yes@rabee
5th Nov 2017, 1:41 AM
Pranit Gandhi
Pranit Gandhi - avatar
+ 2
// this is my answer, correct me if i wrong #include <bits/stdc++.h> using namespace std; char lower(char c) { if(c >= 'A' && c <= 'Z') return c-'A'+'a'; return c; } int main() { string s; cin >> s; bool memo[26]; memset(memo, false, sizeof memo); int longest= -1, indeks =1, count=1,i=1, answer; memo[(int)lower(s[0])-'a']=true; while(i < (int)s.size()) { char c = lower(s[i]); if(memo[(int)c-'a']) //visited { if(count > longest ){ longest = count; answer = indeks; } indeks++; count = 0; memset(memo,false,sizeof memo); } else { memo[(int)c-'a'] = true; count++; i++; } } if(count > longest ){ longest = count; answer = indeks; } cout<<answer<<endl; return 0; }
3rd Nov 2017, 9:30 AM
ramabena
ramabena - avatar
+ 2
@ramabena your code executing without an error.. but showing wrong output... my largest String size is 7 but your program shows output as 4... check it out correct it
3rd Nov 2017, 2:15 PM
Pranit Gandhi
Pranit Gandhi - avatar
3rd Nov 2017, 4:21 PM
ramabena
ramabena - avatar
+ 1
yes it's working brother nice approch
3rd Nov 2017, 4:43 PM
Pranit Gandhi
Pranit Gandhi - avatar
+ 1
Here is my solution. https://code.sololearn.com/cOziFIVWuy5V/#py Also enabled it to print all strings that have an equal length to the largest string length.
4th Nov 2017, 3:34 PM
Paul van Schalkwyk
Paul van Schalkwyk - avatar
+ 1
in other words u want the program to return the longest sequence of charachters without any repetition, right?
4th Nov 2017, 4:17 PM
Rabee Abbas
Rabee Abbas - avatar
3rd Nov 2017, 8:54 PM
VcC
VcC - avatar