C Language Programming advanced 1th Week programming problem

Source: Internet
Author: User
Tags first string

1th Week Programming Questions

View Help

Return

In accordance with the terms of academic integrity, I guarantee that this work is done independently.

Warm tips:

1. This assignment belongs to the online Judge topic and is enigmatic grading by the system immediately after submission.

2. Students can submit an unlimited number of answers before the deadline , and the system will take the highest score as the final result.

1

String alignment (10 points)

Topic content:

The topic is very simple, you will read two strings, each string occupies a row, each string length is less than 10000 characters, and the length of the first string is less than the second string. Your program wants to find out where the first string appears in the second string, output these locations, and if not, output-1.

Note that the position of the first character is 0.

Note that the first string may be in more than one place in the second string.

Note that the string may contain spaces.

Note that the length of the two string must be greater than 0.

Input format:

Two strings, one line at a.

Output format:

The position where the first string appears in the second string, in the order from small to the next, with a space behind each number.

If the first string is not found in the second string, output-1.

Input Sample:

Abba

Ababbba ABBABBABBABBAACC

Sample output:

8 11 14 17

Time limit: 500ms memory limit: 32000kb

1 //2 //main.c3 //CC4 //5 //Created by Anzhongyin on 2016/12/10.6 //Copyright 2016 Anzhongyin. All rights reserved.7 //8 9#include <stdio.h>Ten#include <stdlib.h> One#include <string.h> A intMainintargcConst Char*argv[]) { -     //Insert code here ... -     CharC; the     intI=0; -     Charstr[ +]={' /'};//Large String -     Chardest[ -]={' /'};//Sub-string -     Char*q=0; +     Char*p=0; -     intb=1;//bool,b=0, the first string found in the second string, otherwise 1 +      while((C=getchar ())! ='\ n')//read-in substring A     { atdest[i]=C; -i++; -          -          -     } -I=0; in      while((C=getchar ())! ='\ n')//read in long string -     { tostr[i]=C; +i++; -          the          *     } $    Panax NotoginsengP=STR;//Assign &str[0] address to P -      the      while((Q=strstr (p,dest))!=null)//assigns the starting bit address of a small string of large strings to Q +     { A         CharA=*q;//assigns the value of *q to a to restore the*q=' /';//The position of the first small character in a large string, written in 0, as the end position of the STR string +printf"%lu", strlen (str));//the statistic str length is dest first occurrence position -*q=a;//Restore a string $p=q+1;//start position of the next address of the STR string Q address as the P string $         if(b==1) -b=0;//b=0, the first string found in the second string -     } the     if(b) -printf"-1");Wuyiprintf"\ n"); the      -     return 0; Wu}

C Language Programming advanced 1th Week programming problem

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.