Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

lists occurrences of characters in the string c++

int d[27]={0};
for (int i = 0; i < str.length(); i++)	  //AABBCC
	d[str[i] - 'A']++;
for (int i = 0; i < str.length(); i++) 
	if (d[str[i] - 'A'] != 0) {
		cout << str[i] << " "<< d[str[i] - 'A'] << " "; //A 2 B 2 C 2 
}
 
PREVIOUS NEXT
Tagged: #lists #occurrences #characters #string
ADD COMMENT
Topic
Name
7+7 =