fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main(int argc, char **argv)
  7. {
  8. char array[7] = {'A', 'A', 'B', 'B', 'A', 'G', 'A'};
  9. map<char, int> letter_count;
  10. for(int i = 0; i < 7; ++i)
  11. {
  12. ++letter_count[array[i]];
  13. }
  14. map<char, int>::iterator iter;
  15. int repeat_letter_count = 0;
  16. for(iter = letter_count.begin(); iter != letter_count.end(); ++iter)
  17. {
  18. repeat_letter_count += (*iter).second - 1;
  19. }
  20. cout << "Number of repeated letters: " << repeat_letter_count << endl;
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
Number of repeated letters: 4