CF 8A Train and Peter
来源:互联网 发布:淘宝卖家在哪找淘小二 编辑:程序博客网 时间:2024/05/16 08:58
前些日子看了一看 string 的用法 没想到水到了这题
find函数如果找不到 返回值为 -1 ?
题意 正向反向顺序查找字串 如果只有正向能找到 输出 forward 如果反向能找到 输出 backwards 如果双向都能找到 输出both 找不到 输出 fantasy
#include <iostream>#include <string>using namespace std;int main(){ string a,b,c; string ret; while(cin>>a>>b>>c) { ret = ""; for(int i = a.size()-1;i >= 0;i --) ret += a[i]; int fb = a.find(b,0),fc = a.find(c,fb+b.size()); int bb = ret.find(b,0),bc = ret.find(c,bb+b.size());// cout<<fb<<" "<<fc<<" "<<bb<<" "<<bc<<endl; if((fb == -1 || fc == -1) && (bb == -1 || bc == -1)) cout<<"fantasy"<<endl; else if(fb != -1 && fc != -1 && bb != -1 && bc != -1) cout<<"both"<<endl; else if(fb != -1 && fc != -1 && (bb == -1 || bc == -1)) cout<<"forward"<<endl; else cout<<"backward"<<endl; } return 0;}
0 0
- CF 8A Train and Peter
- cf 8a Train and Peter
- 8A - Train and Peter
- 【String::find】#8 A. Train and Peter
- CodeForces 8A - Train and Peter
- CodeForces 8A Train and Peter (简单模拟题)
- Codeforces Beta Round #8 A. Train and Peter KMP
- Codeforces Beta Round #8A Train and Peter (string的运用)
- CF 553E Kyoya and Train
- cf#339-C - Peter and Snow Blower-简单几何
- CF Peter and Snow Blower 简单计算几何
- CodeForces 613A Peter and Snow Blowe
- codeforces 613A Peter and Snow Blower
- CodeForces 613 A. Peter and Snow Blower(计算几何)
- (CF)A. Vanya and Cards
- A. Gabriel and Caterpillar(cf)
- cf,A. Mashmokh and Lights
- cf 760A Petr and a calendar
- 用MFC写一个随机抽号的软件(VS2013)
- 百度贴吧BDUSS获取器
- 关于HTML5中Video标签无法播放mp4的解决办法
- LeetCode 3Sum Closest
- CMake编译
- CF 8A Train and Peter
- 2015061805 - 10年程序开发经验总结(2)
- poj 3069 Saruman's Army
- 拐卖儿童是否该一律判死刑”你的观点是?
- Maven安装
- 联网温控器的测试
- 正则表达式口诀
- 百度贴吧csrf让全吧吧友在自己都不知情的情况下帮你投诉指定贴吧吧主的bug
- 解决远程连接mysql很慢的方法(mysql_connect 打开连接慢)