+ 25
Is there another way ?
for this code is there another way to don't request length of the input from user and limit the loop (to don't results timelimit exceed) ? https://code.sololearn.com/c6GlSgKW3f4a/?ref=app
2 Réponses
+ 12
Input a string instead. Use a for each loop to do the conversion, or whatever the loop contents are.
std::string v;
std::cin >> v;
for (char i : v) {
// your stuff.
}
// or
for (int i = 0; i < v.length(); i++) {
// your stuff.
}
C++ STL ( <algorithm> ) also has std::transform and ::tolower, which you can use to convert a string to lowercase, if you don't want to manually do the conversion.
std::transform(v.begin(), v.end(), v.begin(), ::tolower);