PAT 10-1 find the specified character in the string, pat10-1

Source: Internet
Author: User

PAT 10-1 find the specified character in the string, pat10-1

Baidu's practices of the other two are to judge whether a match is matched first, and then use a for () loop output. Of course, I also judge it first, and then directly puts (), the question setting requirements and code implementation are as follows:

/* Name: Copyright: Author: Date: 03/04/15 Description: enter a string S and a character c. Search for the character c in string S. If Not found, "Not found" is output. If Not found, all characters starting from c in string S are output. Input Format: enter a non-empty string of no more than 80 characters ending with a carriage return in line 1st, and a character in line 2nd. Output Format: output results in one row according to the requirements of the question. Input Example 1: It is a black boxb output Example 1: black box input Example 2: It is a black boxB output Example 2: not found */# include <stdio. h> # include <string. h> # include <stdbool. h> # define MAX 80 void print (char * S, int l, char c); int main () {// freopen ("in.txt", "r", stdin ); // for test char S [80], c; int l; gets (S); l = strlen (S); c = getchar (); print (S, l, c); // fclose (stdin); // for test return 0;} void print (char * S, int l, char c) {int I; for (I = 0; I <l; I ++) {if (S [I] = c) {puts (S + I); break ;}} if (I = l) printf ("Not found \ n ");}

 

Related Article

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.