can u explain how to take inputs in this question
How to take inputs without knowing size of array
Hello @kunal132k
take input as string then split extract integers and store them in array.
you can take input in this way.
Happy Learning!!
#include<bits/stdc++.h>
using namespace std;
vector split (const string &s, char delim) {
vector result;
stringstream ss (s);
string item;
while (getline (ss, item, delim)) {
result.push_back (item);
}
return result;
}
int main() {
string input;
cin>>input;
string s = input.substr(1,input.length()-2);
//cout<<s;
vector v = split (s, ‘,’);
int k;
cin>>k;
int n=v.size();
int prefix[n];
int sum=0;
for(int i=0;i<n;i++){
string number = v[i];
int num = stoi(number);
sum += num;
prefix[i]=sum;
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.