美团点评 测试开发笔试 2019/10/16 15:00


第一题  美团集体照  50%
时间限制:C/C++语言 1000MS;其他语言 3000MS
内存限制:C/C++语言 65536KB;其他语言 589824KB
题目描述:

美团某部门在拍年度纪念照时,一般要求员工按照 非递减 的高度顺序排列。

请你返回至少有多少个员工没有站在正确位置数量。该人数指的是:能让所有员工以 非递减 高度排列的必要移动人数。

例如:有高度为 1,1,4,2,1,3 的6个学生

共有3个学生没有站在正确的位置(高度为 4、3 和最后一个 1 的学生,没有站在正确的位置)

如遇到空输入的情况,需输出0


#include <stdio.h>
#include <stdlib.h>
int *test(int *arr,int len){
    int *p=(int *)malloc(len*sizeof(int));
    for(int i=0;i<len;i++){
        p[i]=arr[i];
    }
    for(int i=1;i<=len-1;i++){
        int isSwap=0;
        for(int j=0;j<=len-i-1;j++){
            if(p[j]>p[j+1]){
                int temp=p[j];
                p[j]=p[j+1];
                p[j+1]=temp;
                isSwap=1;
            }
        }
        if(isSwap==0){
            break;
        }
    }
    return p;
}
int main(void){
    char str[1000];
    int num[100];
    scanf("%s",str);
    if(str[0]='\0'){
        printf("%d\n",0);
        return 0;
    }
    
    printf("%s\n",str);
    int i=0;
    int temp=0;
    int count=0;
    while(str[i]!='\0'){
        temp=temp*10+str[i]-'0';
        if(str[i+1]==',' || str[i+1]=='\0'){
            num[0]=temp;
            temp=0;
            count++;
            if(str[i+1]==','){
                i++;
            }
        }
        i++;
    }
    int *p=test(num,count);
    int nn=0;
    for(int k=0;k<count;k++){
        if(p[k]!=num[k]){
            nn++;
        }
    }
    printf("%d\n",nn);
    return 0;
}
第二题  寻找最小字符串  17%  来不及了
时间限制:C/C++语言 1000MS;其他语言 3000MS
内存限制:C/C++语言 65536KB;其他语言 589824KB
题目描述:

小美和小团在玩一个游戏,小美任意给出一个大字符串str1以及一个独立的小字符串str2,小团需要从这个大字符串str1里找到包含独立小字符串str2中所有字符的最小子字符串str3;

* 例如,小美给出一个大字符串"meituan2019"和一个子字符串"i2t",那么小团给出的答案就应该是"ituan2";

需要注意:

1、str1中有可能没有完整包含str2所有字符的情况,此时返回"";

2、str1不会为空,但str2有可能为空,此时返回整个str1;

3、str2可能存在重复的字符,此时str3需要包含相等数量该字符;


int test(char *big,char *small){
    int i=0;
    while(small[i]!='\0'){
        int j=0;
        int isFind=0;
        while(big[j]!='\0'){
            if(small[i]==big[j]){
                isFind=1;
                break;
            }
            j++;
        }
        if(isFind==0){
            return 0;
        }
        i++;
    }
    return 1;
}
int main(void){
    char big[1000];
    char small[100];
    scanf("%s",big);
    scanf("%s",small);
    if(small[0]='\0'){
        printf("%s\n",big);
    }else if(test(big,small)==0){
        printf("%s\n","");
    }
}


#笔试题目##美团##秋招##测试开发工程师#
全部评论
两个题目都不一样 😂
点赞 回复
分享
发布于 2019-10-16 17:08

相关推荐

2 16 评论
分享
牛客网
牛客企业服务