牛客网刷题11(2道题)

21.旋转数组的最小数字

题目链接
https://www.nowcoder.com/practice/9f3231a991af4f55b95579b44b7a01ba?tpId=13&&tqId=11159&rp=1&ru=/activity/oj&qru=/ta/coding-interviews/question-ranking
题目描述
把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。
输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素。
例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。
NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。
题目分析
输出数组中元素的最小值。

function minNumberInRotateArray(rotateArray)
{
    if(rotateArray.length ==0 || rotateArray==null){
        return 0;
    }
    return Math.min.apply(Math,rotateArray);
    
}

22.计算字符个数

题目链接
https://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1?tpId=37&&tqId=21225&rp=4&ru=/activity/oj&qru=/ta/huawei/question-ranking
题目描述
写出一个程序,接受一个由字母和数字组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写。
输入描述
第一行输入一个有字母和数字以及空格组成的字符串,第二行输入一个字符。
输出描述
输出输入字符串中含有该字符的个数。
示例1
输入
ABCDEF
A
输出
1
题目分析
判断输入的一个字符的大小写。

#include<stdio.h>
#include<string.h>
int main(){
    char str[1000];
    gets(str);
    char x;
    scanf("%c",&x);
    int num=0;
    int len;
    len = strlen(str);
    if(x>='a' && x<='z'){
        for(int i=0;i<len;i++){
            if(str[i] == x || str[i] == x - 32){
                num++;
            }
        }  
    }
    if(x>='A' && x<='Z'){
        for(int i=0;i<len;i++){
            if(str[i] == x || str[i] == x + 32){
                num++;
            }
        }  
    }
     
    printf("%d",num);
    return 0;
     
}
发布了22 篇原创文章 · 获赞 0 · 访问量 366

猜你喜欢

转载自blog.csdn.net/weixin_41796393/article/details/104256549