• 练习7-10 查找指定字符 (15分)


    本题要求编写程序,从给定字符串中查找某指定的字符。

    输入格式:

    输入的第一行是一个待查找的字符。第二行是一个以回车结束的非空字符串(不超过80个字符)。

    输出格式:

    如果找到,在一行内按照格式“index = 下标”输出该字符在字符串中所对应的最大下标(下标从0开始);否则输出"Not Found"。

    输入样例1:

    m
    programming
    
     

    输出样例1:

    index = 7
    
     

    输入样例2:

    a
    1234
    
     

    输出样例2:

    Not Found

    #include<stdio.h>
    #include<string.h>
    int main()
    {
        char c,str[81];
        int i,index=-1;
    //  c=getchar();
    scanf("%c ",&c);
        gets(str);
        for(i=0;str[i]!='';i++)
        {
            if(c==str[i])
            {
                index=i;
            }
        }
            if(index!=-1)
            {
                printf("index = %d",index);
            }   else
            {printf("Not Found");
            }

        return 0;
    }



  • 相关阅读:
    Python之路,day16-Python基础
    Python之路,day15-Python基础
    Python之路,day14-Python基础
    django之model操作
    django信号
    django缓存
    CSRF的攻击与防范
    cookie和session
    http协议之Request Headers
    ajax参数详解
  • 原文地址:https://www.cnblogs.com/wven/p/12727551.html
Copyright © 2020-2023  润新知