Wikioi 1204 find the substring position (strstr () function)

Source: Internet
Author: User
1204 locate a substring Description

The string a and string B are given to ensure that B is a substring of A. Please output the position where B first appears in.

Input description Input description

Only one line contains two strings A and B

Output description Output description

Only one integer in one row

Sample Input Sample Input

ABCD BC

Sample output Sample output

2

Data range and prompt Data size & hint

The length of a string cannot exceed 100

Note to Pascal: two strings may contain multiple spaces.

 

 

Pass code:

  

  

#include <stdio.h>#include <string.h>int main(){char a[100], b[100], *ptr1, *ptr2;scanf("%s%s", a, b);ptr1 = &a;ptr2 = strstr(a, b);printf("%d", (ptr2 - ptr1) + 1);return 0;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.