Scan text: count, filter, transform
Build a result from matching characters without losing leading zeros or skipping shifted text.
One character, one decision
String traversal is an array scan whose elements are characters. A local char c = s[i] is a copy: assigning to c does not update s[i]. Write to the actual indexed character when you intend a change.
To count vowels, write a complete equality for each accepted letter and join them with ||. c == 'a' || 'e' is wrong because the second operand is a nonzero character value, not another comparison. Decide whether uppercase counts from the task.
Build filtered output separately
Filtering retains only characters satisfying a rule, in their original order. Begin with an empty result and append accepted characters. Removing characters while moving forward through the same string can shift the next character into an index you have already passed.
This example reads one ASCII line of at most 100000 characters. It retains digit characters and independently sums their numeric values. For room 20B, floor 3, it produces 203 and 5.
#include <iostream>
#include <string>
int main() {
std::string s;
std::getline(std::cin, s);
std::string digits;
int sum = 0;
int n = static_cast<int>(s.size());
for (int i = 0; i < n; ++i) {
if ('0' <= s[i] && s[i] <= '9') {
digits.push_back(s[i]);
sum += s[i] - '0';
}
}
std::cout << digits << '\n' << sum << '\n';
return 0;
}A huge number can remain text
A 100000-digit integer cannot fit a built-in integer type, but its digit sum still needs only a scan. Its maximum possible digit sum is 9 × 100000 = 900000, which fits the training environment’s int.
Keeping a string preserves leading zeros: a09b2 filters to 092, with sum 11. Converting the whole result to an integer would change its representation. Other tasks can set flags for uppercase, lowercase, and digit categories, then combine those flags with a minimum-length condition.
The digit filter receives a09b2. What text and digit sum does it produce?
Turn the idea into code
Read one lowercase ASCII word of length at most 100000. Remove the vowels a, e, i, o, u and print the remaining characters in order.
Give me a hint
Use a fresh result string. Append only when the complete vowel condition is false.
Show the explained solution
The source word remains unchanged during traversal, so no indices shift. A word containing only vowels produces an empty output line.
#include <iostream>
#include <string>
int main() {
std::string s;
std::cin >> s;
std::string result;
int n = static_cast<int>(s.size());
for (int i = 0; i < n; ++i) {
char c = s[i];
bool vowel = c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
if (!vowel) { result.push_back(c); }
}
std::cout << result << '\n';
return 0;
}Your notes
Mark complete when you can explain it yourself.