码迷,mamicode.com
首页 > 其他好文 > 详细

字串的先后顺序

时间:2016-09-11 01:23:25      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <string>
 5 #include <stdlib.h>
 6 using namespace std;
 7 
 8 int main(int argc, char * argv[])
 9 {
10     char mn[10000] = {0};
11     char first[100] = {0};
12     char second[100] = {0};
13     while (scanf("%s", mn) != EOF) {
14         getchar();
15         string str(mn);
16         int i;
17         scanf("%s", first);
18         getchar();
19         string fstr(first);
20         scanf("%s", second);
21         getchar();
22         string sstr(second);
23 
24         int idxf = str.find(fstr, 0);
25         int idxfr = str.rfind(fstr);
26         int idxs = str.find(sstr, 0);
27         //int idxsr = str.find(sstr, 0);
28         if((idxf == string::npos) || (idxs == string::npos)){
29             cout << "invalid" << endl;
30         }
31 
32         if((idxfr > idxf) && (idxf < idxs) && (idxfr > idxs)){
33             cout << "both" << endl;
34         }
35 
36         if (idxfr == idxf)
37             if(idxf < idxs){
38                 cout << "forward" << endl;
39             }else if(idxf > idxs){
40                 cout << "backward" << endl;
41             }
42 
43 
44     }
45     return 0;
46 }
View Code

 

eg:
input:
atob
a
b
output:
forwad

aacacaa
cac
aa
output:
both

字串的先后顺序

标签:

原文地址:http://www.cnblogs.com/guxuanqing/p/5860720.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!