#include <string>
#include <map>
#include <iostream>
using namespace std;
int main()
{
string s = "cchh";
map<char,int> first_index;
for(int i = 0; i < s.size(); i++)
{
if(first_index[s[i]] == 0)
first_index[s[i]] = i+1;
cout << i+1 << " " << first_index[s[i]] << " " << (i+1==first_index[s[i]]) << endl;
}
}
Output:
Index of character, first index of character, first index = index of character
1 1 1
2 1 0
3 3 1
4 3 0
I'm not certain if this is right, because your description of the numbers in the list was still not clear.