|
Time |
Memory |
Case 1 |
1 sec |
32 MB |
Case 2 |
1 sec |
32 MB |
Case 3 |
1 sec |
32 MB |
Case 4 |
1 sec |
32 MB |
Case 5 |
1 sec |
32 MB |
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.
Tags