Is there another way ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

28th May 2018, 2:28 PM
AliR૯za
AliR૯za - avatar
1 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);
28th May 2018, 2:36 PM
Hatsy Rei
Hatsy Rei - avatar