Output?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Output??

You have to get a new driver's license and you show up at the office at the same time as 4 other people. The office says that they will see everyone in alphabetical order and it takes 20 minutes for them to process each new license. All of the agents are available now, and they can each see one customer at a time. How long will it take for you to walk out of the office with your new license? Sample:. "Zyzz" 1 "Andy Gara Typo Lobster" #include <iostream> using namespace std; int main() { string n,a; int j; getline(cin,n); cin>>j; getline(cin,a); int d=0,i; if(n[0]>a[0]) d++; for(i=1;i<(int)a.length();i++){ if((int)a[i]==32){ if(n[0]>a[i+1]) d++; } } int m; m=(d/j)+1; cout<<m*20; return 0; }

5th Oct 2022, 8:38 PM
RAESEN
RAESEN - avatar
1 Answer
+ 2
"cin" leaves '\n' behind. getline() reads the line to the end until it encounters a separator character, (default '\n'). As a result, it turns out that getline(cin, a) reads the character '\n' remaining after "cin", assigning it to the variable 'a' and stops. You must read the remaining '\n' character before entering new data using the getline() function: #1: (cin>>j).get(); getline(cin,a); #2: cin>>j; getline(cin,a); getline(cin,a); #3 cin>>j; getline(cin,a,'.'); Or: cin>>j>>a;
6th Oct 2022, 12:31 PM
Solo
Solo - avatar