Is there another way ? | Sololearn: Learn to code for FREE!

+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

5/28/2018 2:28:17 PM

AliR૯za

2 Answers

New Answer

+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);