Jumping onto next string when the condition is met
Posted
by
user98235
on Stack Overflow
See other posts from Stack Overflow
or by user98235
Published on 2014-08-20T15:52:30Z
Indexed on
2014/08/20
16:20 UTC
Read the original article
Hit count: 187
This was a problem related to one of the past topcoder exam problems called HowEasy.
Let's assume that we're given a sentence, for instance,
"We a1re really awe~~~some"
I just wanted to take get rid of every word in the sentence that doesn't contain alphabet characters, so in the above sentence, the desired output would be
"We really"
The below is the code I wrote (incomplete), and I don't know how to move on to the next string when the condition (the string contains a character that's not alphabet) is met. Could you suggest some revisions or methods that would allow me to do that?
vect would be the vector of strings containing the desired output
string param;
cin>>param;
stringstream ss(param);
vector<string> vect;
string c;
while(ss >> c){
for(int i=0; i < c.length(); i++){
if(!(97<=int(c[i])&&int(c[i])<=122) &&
!(65<=int(c[i])&&int(c[i])<=90)){
//I want to jump onto next string once the above condition is met
//and ignore string c;
}
vect.push_back(c);
if (ss.peek() == ' '){
ss.ignore();
}
}
}
© Stack Overflow or respective owner