mingmingfly
BAN USERbool isMatch(const char *s, const char *p) {
if (*p == '\0') return *s == '\0';
// next char is not '*', then must match current character
if (*(p + 1) != '*') {
if (*p == *s || (*p == '.' && *s != '\0'))
return isMatch(s + 1, p + 1);
else
return false;
}
else {
if(*p == *s || (*p == '.' && *s != '\0'))
return isMatch(s, p + 2) || isMatch(s+1,p+2);
else return false;
}
}
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string reverseWords(string str){
string res="";
int n=str.length();
if(n==0) return res;
int i=0;
int start = 0;
int len=0;
string w="";
while(i<n){
if(str[i++]!=' ')
len++;
else if(i<n&&str[i]!=' '){
w=str.substr(start,len);
reverse(w.begin(),w.end());
res=res+w+" ";
start = i;
len=0;
}
}
w=str.substr(start,len);
reverse(w.begin(),w.end());
res=res+w;
return res;
}
- mingmingfly November 23, 2014