【无标题】

1.题目描述

解题思路

先在行里面查找出最大值,再从找到的这个最大值所在列判断是否有其他数比行最大值小,找到了,说明find为0

C语言实现

cpp 复制代码
#include <stdio.h>
int main()
{
    int m,n;
    scanf("%d %d",&m,&n);
    int Array[m][n];
    int find = 0;
    int row;
    for(int i = 0;i < m;i++){
        for(int j = 0;j < n;j++){
            scanf("%d",&Array[i][j]);
        }
    }
    for(int i = 0;i < m;i++){
        row = 0;
        for(int j = 1;j < n;j++){
            if(Array[i][j]>Array[i][row]){
                row = j;
            }
        }
        int min = 1;
        for(int k = 0;k <m;k++){
            if(Array[i][row]>Array[k][row]){
                min = 0;
                break;
            }
        }
        if(min){
            printf("Array[%d][%d]=%d",i,row,Array[i][row]);
            find = 1;
            break;
        }
    }
    if(!find){
        printf("None");
    }
    return 0;
}

2.题目描述

解题思路

汉诺塔问题,

1.把n-1个金片从from移到to,借助temp

2.把第n个金片从from移到to;

3.把第n-1个金片从temp移到to借助from

C语言实现

cpp 复制代码
#include <stdio.h>
void hanoi(int n,char from,char temp,char to)
{
    if(n == 1){
        printf("Move disk %d from %c to %c\n",n,from,to);
        return;
    }
    hanoi(n - 1,from,to,temp);
    printf("Move disk %d from %c to %c\n",n,from,to);
    hanoi(n - 1,temp,from,to);

}
int main()
{
    int n;
    scanf("%d",&n);
    hanoi(n,'A','B','C');
    return 0;
}

3.题目描述

解题思路

定义字符串实际是定义一个二维数组,然后定义将str0设为min,str1设为mid,str2设为min;

分别与其他值作比较进行交换

C语言实现

cpp 复制代码
#include <stdio.h>
#include <string.h>
int main()
{
    char str[3][100];
    char temp[100];
    scanf("%s %s %s",str[0],str[1],str[2]);
    if(strcmp(str[0],str[1])>0){
        strcpy(temp,str[0]);
        strcpy(str[0],str[1]);
        strcpy(str[1],temp);
    }
    if(strcmp(str[0],str[2])>0){
        strcpy(temp,str[0]);
        strcpy(str[0],str[2]);
        strcpy(str[2],temp);
    }
    if(strcmp(str[1],str[2])>0){
        strcpy(temp,str[1]);
        strcpy(str[1],str[2]);
        strcpy(str[2],temp);
    }
    printf("%s %s %s",str[0],str[1],str[2]);
    return 0;
}

4.题目描述

解题思路

看子串个数,先要比较检验母串与子串的长度大小,先处理特殊情况(子串>母串,子串为0)

再循环查找匹配的起始位置,与子串各个字符相对比,若全部匹配count++,最后输出的是count 的值,i记得要跳过重叠部分

C语言实现

cpp 复制代码
#include <stdio.h>
#include <string.h>
int main()
{
    char str[100];
    char s[100];
    scanf("%s",str);
    scanf("%s",s);
    int count = 0;
    int len_str = strlen(str);
    int len_s = strlen(s);
    if(len_s > len_str||len_s == 0){
        printf("0");
    }
    for(int i = 0;i <= len_str-len_s;i++){
        int match = 1;
        int j,k;
        for( j = 0, k = i;j < len_s;j++,k++){
            if(str[k]!=s[j]){
                match = 0;
                break;
            }
        }
        if(match){
            count++;
            i = i +len_s-1;
        }
    }
    printf("%d",count);
    return 0;
}
相关推荐
leobertlan6 小时前
痛苦系列 | DSP-03 跨越单位圆:Z变换与零极点分析
算法·程序员
蛋蛋的就会顺顺的6 小时前
hot100 p0——栈,贪心算法,动态规划
java·前端·javascript·算法·leetcode·力扣
开发小能手1237 小时前
答案daanC语言
数据结构·算法
Navigator_Z8 小时前
LeetCode //C - 1291. Sequential Digits
c语言·算法·leetcode
pride.li9 小时前
第03章 Python 教程-基础语法:注释与变量
服务器·前端·后端·python·算法·计算机视觉
旺仔仔仔10 小时前
机器人项目实战(5):从单次抓取,到接收指令连续做事
算法
旺仔仔仔10 小时前
机器人项目实战(2):识别物体、提取点云,再到抓取姿态
算法
姜鱼问生10 小时前
密码明明一样,为什么 GPG 说“错的“?
后端·算法·架构
启观川11 小时前
数据结构与算法-第 3 章 常用算法-贪心算法
数据结构·笔记·python·算法·贪心算法
对空六课11 小时前
指标口径生效时间的版本查询实现
大数据·服务器·前端·算法·数据分析