zoukankan      html  css  js  c++  java
  • 第四届蓝桥杯c/c++B组5

    如下的代码判断 needle_start指向的串是否为haystack_start指向的串的前缀,如不是,则返回NULL。
    比如:"abcd1234" 就包含了 "abc" 为前缀

    char* prefix(char* haystack_start, char*needle_start)

    {
           char*haystack = haystack_start;
           char*needle = needle_start;    
           while(*haystack&& *needle){
                 ———————— return NULL;  //填空位置
           }
           if(*needle)return NULL;
           return haystack_start;
    }

    请分析代码逻辑,并推测划线处的代码,通过网页提交。

    #include<iostream>
    using namespace std;
    char* prefix(char* haystack_start, char* needle_start)  {  
        char* haystack = haystack_start;  
        char* needle = needle_start;    
        while(*haystack && *needle){  
            if(*(haystack++)!=*(needle++)) return NULL;  //填空位置  
        }     
        if(*needle) return NULL;        
        return haystack_start;  
    }  
    int main(){
     char a[]="abc1234";
     char b[]="abc";
     cout<<prefix(a,b);
     return 0;
    }
    

      

    注意:仅把缺少的代码作为答案,千万不要填写多余的代码、符号或说明文字!!

  • 相关阅读:
    FineReport——函数
    FineReport——插入行策略
    FineReport——JS二次开发(CSS改变控件样式)
    FineReport——JS二次开发(下拉框)
    汽车系统
    Ubuntu Software setup
    Win 10 乱码 & 字体横过去了
    U-boot 2016.11 代码结构 dra7xx
    samba Ubuntu 16.04
    ftp Ubuntu16.04
  • 原文地址:https://www.cnblogs.com/a863886199/p/6581004.html
Copyright © 2011-2022 走看看