It seems everything works, but according to the condition of the teacher, the characters and upper case should be taken as the same, that is, "A" == "a". How can this be realized?

Provide the code: `

int main ()

{

char str[255]; int chars[256] = { 0 }; cin >> str; for (int i = 0; str[i]; i++) chars[str[i]]++; for (int i = 0; i < 256; i++) if (chars[i]) cout << char(i) << " zamechen " << chars[i] << " raz" << endl; 

} `

  • one
    Translate the characters in the counting in upper case. - Harry

1 answer 1

  for (int j = 0; j <= 255; j++) if (str[j]>0) str[j] = toupper(str[j]); 

Before this, you must connect the header file "algorithm"

  • one
    Instead of a clever if I would just do str[j] = toupper((unsigned char)str[j]); . And inclusion is not <algorithm> , but <cctype> . - HolyBlackCat pm