#include <iostream>
#include <string>
using namespace std;
#define MAX_CHARS 256
int LengthOfLongestSubstring(string s)
{
int chars[MAX_CHARS];
for (int i = 0; i < MAX_CHARS; ++i)
chars[i] = -1;
int longest = 0;
int start = 0;
int sLength = s.size();
for (int i = 0; i < s.size(); ++i)
{
if (chars[s[i]] >= 0)
{
int len = i - start;
if (longest < len) longest = len;
while(start <= chars[s[i]])
chars[s[start++]] = -1;
}
chars[s[i]] = i;
}
int len = sLength - start;
if (longest < len)longest = len;
return longest;
}
int main(int argc, char** argv)
{
string s = "abc";
cout << s << ": " <<LengthOfLongestSubstring(s) << endl;
s = "abcdefghhaijklmn";
cout << s << ": " <<LengthOfLongestSubstring(s) << endl;
s = "aaaaaaaaaaaa";
cout << s << ": " <<LengthOfLongestSubstring(s) << endl;
return 0;
}