http://codevs.cn/problem/1204/

1204 寻找子串位置

 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 青铜 Bronze
 查看运行结果
 
 
题目描述 Description

给出字符串a和字符串b,保证b是a的一个子串,请你输出b在a中第一次出现的位置。

输入描述 Input Description

仅一行包含两个字符串a和b

输出描述 Output Description

仅一行一个整数

样例输入 Sample Input

abcd bc

样例输出 Sample Output

2

数据范围及提示 Data Size & Hint

字符串的长度均不超过100

Pascal用户请注意:两个字符串之间可能包含多个空格

分析:

数据量不是很大,直接对字符串进行匹配即可。

AC代码:

 /*
作者:1348066599@qq.com
题目:p1204 寻找子串位置
*/ #include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <iomanip>
#include <vector>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#pragma warning(disable:4786) using namespace std; const int INF = 0x3f3f3f3f;
const int MAX = + ;
const double eps = 1e-;
const double PI = acos(-1.0); int main()
{
char str[] , str1[];
while(cin >> str >> str1)
{
int i , j , ans = ;
int len = strlen(str);
int len1 = strlen(str1);
for(i = ;i < len - len1 + ;i ++)
{
int ii = i , k = ;
for(j = ;j < len1;j ++)
if(str1[j] == str[ii ++])
k ++;
else
break;
if(j == len1)
{
ans = i + ;
break;
}
}
printf("%d\n",ans);
}
return ;
}

codevs 1204 寻找子串位置的更多相关文章

  1. codevs 1204 寻找子串位置 KMP

    1204:寻找子串位置 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 18K  Solved: 8K Description 给出字符串a和字符串b,保 ...

  2. wikioi 1204 寻找子串位置

    /*======================================================================== 1204 寻找子串位置 题目描述 Descript ...

  3. C++之路进阶——codevs1204(寻找子串位置)

    1204 寻找子串位置  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 青铜 Bronze     题目描述 Description 给出字符串a和字符串b,保证b是a的一个子 ...

  4. 寻找子串位置 codevs 1204

    题目描述 Description 给出字符串a和字符串b,保证b是a的一个子串,请你输出b在a中第一次出现的位置. 输入描述 Input Description 仅一行包含两个字符串a和b 输出描述  ...

  5. 寻找子串位置<codevs>

    KMP板子题; 如果不会可以参考其他算法书 代码: #include<iostream> #include<stdio.h> #include<stdlib.h> ...

  6. codevs1204 寻找子串位置

    题目描述 Description 给出字符串a和字符串b,保证b是a的一个子串,请你输出b在a中第一次出现的位置. 输入描述 Input Description 仅一行包含两个字符串a和b 输出描述  ...

  7. CODE[VS]-寻找子串位置-字符串处理-天梯青铜

    题目描述 Description 给出字符串a和字符串b,保证b是a的一个子串,请你输出b在a中第一次出现的位置. 输入描述 Input Description 仅一行包含两个字符串a和b 输出描述 ...

  8. 匈牙利算法 codevs 2776 寻找代表元

    codevs 2776 寻找代表元  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题目描述 Description 广州二中苏元实验学校一共有n个社团,分别用 ...

  9. 【CodeVS】1204 寻找字串位置

    题目描述 Description 给出字符串a和字符串b,保证b是a的一个子串,请你输出b在a中第一次出现的位置. 输入描述 Input Description 仅一行包含两个字符串a和b 输出描述  ...

随机推荐

  1. java继承覆盖总结

      Java基础(1)  版权声明:本文为博主原创文章,未经博主允许不得转载. java的继承与覆盖基本是java笔试中常出的题,也比较绕,我这里对java的继承覆盖做一个总结1.构造函数:      ...

  2. CS6破解

    1) 序列号这里为大家生成了两个,可以通过软件验证:1325-0949-2080-9819-3777-32301325-0160-5283-9851-2671-8951 2) 破解补丁安装时会用到,请 ...

  3. Marshal.SecureStringToBSTR

    Marshal.StringToBSTR 方法 命名空间:System.Runtime.InteropServices程序集:mscorlib(在 mscorlib.dll 中) // 使用一个Int ...

  4. linux bq20z75 驱动

    新的项目中使用到了电池.电池的guage使用TI的bq20z75.kernel的驱动中已经有bq20z75的驱动,只要稍加修改就可以使用. 参考链接 http://www.ti.com/lit/er/ ...

  5. bind和unbind事件的应用

    1.bind 先从一动画的示例看起,如图: 而图中表示的mouseout(移出).mouseover(移入)事件的操作,比较简单,具体代码如下: 从中我可以得出bind()的语法: $().bind( ...

  6. Eight Popular Open Source Android Game Engines

    https://software.intel.com/en-us/blogs/2012/05/14/eight-popular-open-source-android-game-engines

  7. Android 关于ExpandableListView刷新的解决办法

    正文 首先是最基础的 ExpandableListView vList = (ExpandableListView) this.findViewById(R.id.list); EListAdapte ...

  8. MSYS2 安装和配置

    MSYS2 安装和配置 msys2 和 cygwin 类似,提供了一个类 Linux 的 shell 环境和工具链,同时还使用了 arch linux 的 pacman 管理软件包,比 cygwin ...

  9. Q promise的使用

    虽然es6已经出现一段时间了,但是对于没有使用es6的node.js的时候,仍要解决回调金字塔,因此Q还是很有必要的.

  10. C# 实例化多线程组

    代码如下 //实例化线程组 Thread[] clientThreads = new Thread[numThread]; ; i < numThread; i++) { clientThrea ...