Title Description:
For a given string, find out that there are duplicate characters and give their position, such as: ABCAAAB12AB12
Output: a,1;a,4;a,5;a,10,b,2;b,11,1,8;1,12, 2,9;2,13.
Input:
The input includes a string of letters and numbers that are not more than 100 in length.
Output:
There may be multiple sets of test data, for each set of data,
The position where the character appears is marked by the format of the sample output.
Sample input:
abcaaAB12ab12
Sample output:
a:0,a:3,a:4,a:9b:1,b:101:7,1:112:8,2:12
Tips:
1, subscript starting from 0.
2. The same letter indicates where it has appeared in a line.
#include <iostream>#include<string.h>#include<stdlib.h>using namespacestd;intMain () {Chara[101]; while(Gets (a)) {intLen; Len=strlen (a); intI,j,flag,first; for(i=0; i<len;i++) {flag=1; first=1; if(a[i]!=' ') { for(j=i+1; j<len;j++) { if(a[i]=A[j]) { if(first) {cout<<a[i]<<":"<<i; First=0; } cout<<","<<a[i]<<":"<<i; A[J]=' '; Flag=0; } } } if(flag==0) cout<<Endl; } } return 0;}
1199. Find a location