Please review my code here in C... there are errors occurring and I'm not sure why. InputInput will begin with a line containing 1 integer, n (1 ≤ n ≤ 500,000), representing the number of groups to process. The following n lines will each contain 3 integers: s, a, and p (1 ≤ s ≤ 1,000,000; 1 ≤ a ≤ 1,000,000,000; 1 ≤ p ≤ 1,000,000) representing the group size, arrival time, and processing time respectively. Output should contain 1 integer representing the sum time taken by all people that waited in line. Example: Sample Input: 4 1 4 10 1 2 10 1 1 10 1 3 10 Output: 56 3 2 10 10 3 9 1 1 1 20 Output: 65 Code below: #include #include #include #include #include usingnamespace std; int main() { while(true){ cout<<"\nEnter visitor's data or input xx to stop\n"; string s; getline(cin,s);// Enter the new data line if(s=="xx")//If entered value is xx then stop break; stringstream ss(s);//Conersion of string to numbers of visitors vectorvisitor_count; int x; while(ss>>x){ if(x==888)//If number is sentinel value then stop break; else visitor_count.push_back(x); } string time;// To input string value ss>>time; int total_visitors=0;//To sum up total visitors for(int i=0;i
Please review my code here in C... there are errors occurring and I'm not sure why.
to process. The following n lines will each contain 3 integers: s, a, and p (1 ≤ s ≤ 1,000,000; 1 ≤ a ≤
1,000,000,000; 1 ≤ p ≤ 1,000,000) representing the group size, arrival time, and processing time
respectively.
Output should contain 1 integer representing the sum time taken by all people that waited in line.
4
1 4 10
1 2 10
1 1 10
1 3 10
Output: 56
3
2 10 10
3 9 1
1 1 20
#include<iostream>
#include<string.h>
#include<sstream>
#include<
#include <stdio.h>
usingnamespace std;
int main()
{
while(true){
cout<<"\nEnter visitor's data or input xx to stop\n";
string s;
getline(cin,s);// Enter the new data line
if(s=="xx")//If entered value is xx then stop
break;
stringstream ss(s);//Conersion of string to numbers of visitors
vector<int>visitor_count;
int x;
while(ss>>x){
if(x==888)//If number is sentinel value then stop
break;
else
visitor_count.push_back(x);
}
string time;// To input string value
ss>>time;
int total_visitors=0;//To sum up total visitors
for(int i=0;i<visitor_count.size();i++){
cout<<visitor_count[i]<<" New visitors entered.\n";
total_visitors += visitor_count[i];
}
cout<<"By "<<time<<<"," <<total_visitors<<" new visitors entered the Park\n";
}
return0;
}
Step by step
Solved in 3 steps with 3 images