Input Manipulation
#include<bits/stdc++.h>
using namespace std;
int bar(string s){
// vector<int> ans(2);
int ans=-1;
int s_size=s.size();
int c_ind=-1;
for(int i=0;i<s_size;i++){
if(s[i]==','){
c_ind=i;
break;
}
}
if(c_ind==-1){
// ans[0]=-1;
// ans[1]=-1;
return -1;
}
string temp=s.substr(0,c_ind);
if(temp.size()==1){
return int(char(temp[0]))-48;
}
else{
return stoi(temp);
}
}
int main() {
string st;
int i=0;
int previous_day=0;
while(true){
cout<<"Enter input: ";
getline(cin,st);
int day=bar(st);
cout<<"day is "<<day<<endl;
if(day<previous_day){
cout<<"Invalid!\n";
}
previous_day=day;
}
return 0;
}
Comments
Post a Comment