1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include <iostream>
#include <cstring>
using namespace std;
int next(string s,int i,int j){
for(int k = 0; k<j; k++){
if (s[k] != ' '){
return k+1;}
}
return -1;
}
int prev(string s, int i, int j){
for (int k = j; k>i; k--)
if (s[k] != ' '){
return k-1;
}
return -1;
}
int neq(string s,int i,int j){
for(int k=0;k<j;k++)
if(s[k]!=' '){
return k;
}return -1;
}
int peq(string s,int i,int j){
for(int k=j;k>=i;k--)
if(s[k]!=' '){
return k;}
return -1;
}
void intit(const char * s,int i,int j,int * k, int * l){
for(i=next(s,0,strlen(s));i<prev(s,0,strlen(s));i++){
}
}
int main(){
const char *a="evil olive";
cout << next(a,0,strlen(a))<<endl; // smallest k between
cout << prev(a,0,strlen(a))<<endl; // largest k between
cout << neq(a,0,strlen(a))<<endl; // smallest k between including i end point
cout << peq(a,0,strlen(a))<<endl; // largest k between including j end point
return 0;
}
|