Question description
Write the function int f (char s[ ]), convert all lowercase letters in the string into corresponding uppercase letters, and the other characters remain unchanged, and count the number of converted letters, and return them as function value. Requires that the string be entered into the main function, and finally output the converted new string and the number of converted letters.
Enter a description
Enter a string.
Output description
Two lines, the first line outputs the converted new string, and the second line outputs the converted number of lowercase letters.
Enter sample
ser34GHj
Output sample
SER34GHJ
4
#include <iostream>
#include <cctype>
using namespace std;
int f(char s[]){
int i;
int count = 0;
for(i = 0;s[i] != '\0'; i++){
if(s[i] >= 'a' && s[i] <= 'z') { // Only get the ASCII code of a~z
s[i] -= 32; // Since each letter corresponds to ASCII code, you only need to modify the corresponding ASCII code to achieve lowercase conversion to uppercase
count++;
}
}
return count;
}
int main(void){
char str[128];
int num;
cin >> str;
num = f(str);
cout << str << endl;
cout << num << endl;
}