Time Limit: 2s Memory Limit: 192MB
Problem Description
Input a string of characters, convert uppercase letters to lowercase, and output the original character if it is not uppercase.
Input Format
Any string (length within 100) is terminated by a newline.
Output Format
Output the corresponding lowercase for uppercase letters, and output the original character if it is not uppercase.
Sample Input
A123b
Sample Output
a123b
Code
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main() {
string s;
getline(cin, s);
for (char &c : s) {
if (isupper(c)) {
c = tolower(c);
}
}
cout << s << endl;
return 0;
}
Output Result
Methodology (1) Read Input: Read a line of string. (2) Process: Iterate through each character in the string: If it is an uppercase letter (‘A’ to ‘Z’), convert it to a lowercase letter (by adding 32 or using the built-in function). Otherwise, keep it unchanged. (3) Output Result: Output the processed string.Code Explanation (1) Read Input: Use getline to read a line of string, including spaces. (2) Process: Use a range-based for loop to iterate through each character, using isupper to check if it is an uppercase letter, and if so, convert it to lowercase using tolower. (3) Output Result: Directly output the processed string.Validation ExampleInput: A123bOutput: a123b
C++ Basic Tutorial Collection
C++ Basic Resources
1. C++ Output
2. C++ Variables
3. C++ Input
4. C++ Expressions
5. IF Statements
6. IF Applications
7. WHILE Loops
8. FOR Loops
9. Arrays
10. One-Dimensional Arrays
11. Two-Dimensional Arrays
12. C++ Functions
13. C++ File Operations – Writing Files
If you find it useful, please click on it.



