swustoj字符串查找(0448)
来源:互联网 发布:stc89c51单片机烧录 编辑:程序博客网 时间:2024/05/17 22:35
在一段句子中找出给定字符串出现在句子中第一个字母出现的位置。 句子中字符个数小于4500。 字符串字符个数小于120。
Description
两行 第一行是给定字符串 第二行是句子
Input
整数,字符串出现的位置
Output
1
2
abcde
this is a Example of abcde!
Sample Input
1
22
#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<algorithm>#include<string>using namespace std;int main(){char str1[150];char str2[4505];scanf("%[^\n]s", str1);//坑点,害我wrong了3次//第一个字符串也有可能有空格getchar();scanf("%[^\n]s", str2);//cout << str2 << endl;int flag = 0;int ans = 0;for (int i = 0; i < strlen(str2)&&flag == 0; i++){if (str2[i] == str1[0]){int t = 1;int cnt = 0;for (int j = i + 1; t < strlen(str1)&&cnt == 0; j++, t++){if (str1[t] != str2[j]){cnt++;}}if (cnt == 0){ans = i+1;flag = 1;}}}cout << ans << endl;return 0;}
0 0
- swustoj字符串查找(0448)
- swustoj(字符串查找(0448))
- swustoj前缀字符串(0185)
- (swustoj)二叉排序树的实现和查找(1011)
- swustoj---1091
- swustoj(667)
- 查找字符串
- 查找字符串
- 查找字符串
- 查找字符串
- 查找字符串
- 查找字符串
- 字符串查找
- 字符串查找
- 查找字符串
- 查找字符串
- 字符串查找
- 查找字符串
- java的继承 多态 类和接口
- C#136课的主要内容
- PHP实现的版本号比较
- Ecshop模板开发(十七):商城页面底部帮助信息
- Android如何监听:软键盘显示时:返回键事件
- swustoj字符串查找(0448)
- 图片预加载的几个注意点
- Linux相关命令记录
- ERP安全
- MySQL数据类型
- 单例模式
- spring boot-使用redis的Keyspace Notifications实现定时任务队列
- 24 点游戏
- Linux errno值含义 与 思考(致命与可修正错误类型)