13775 - Hashing   

Description

Given a string str, using hashing to find the index of the first repeating element in it (i.e. the element that occurs more than once and whose index of the first occurrence is the smallest).Then, return the first element.

You may use the code template below and replace /*TODO*/ section with your code.

#include <string.h>
#include <iostream>
using namespace std;
#define MAX_CHAR 256
 
int findRepeatFirst(char* s)
{
   /*TODO*/
}
 
int main()
{
char str[200];
cin >> str;
int pos = findRepeatFirst(str);
if (pos == -1)
cout << "Not found";
else
cout << str[pos];
return 0;
}

Input

Input a string str.

Output

Print the first element to appear twice.

Sample Input  Download

Sample Output  Download

Tags




Discuss