【无标题】

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;
}
相关推荐
烬羽9 小时前
递归老写崩?一个"退回"公式,把回溯题变成填空题
javascript·深度学习·算法
闪电悠米9 小时前
力扣hot100-41.缺失的第一个正数-原地哈希详解
数据结构·算法·哈希算法
WL学习笔记9 小时前
堆(数据结构)
数据结构·
星空露珠10 小时前
28种颜色对应名称,
开发语言·数据库·算法·游戏·lua
QXWZ_IA11 小时前
桥梁数字孪生怎么落地?
人工智能·科技·算法·智能硬件·政务
Kel11 小时前
输出层与反分词(Output Layer & Detokenization)
人工智能·算法·架构
陕西企来客11 小时前
2026年7月技术好GEO优化方案:算法适配与内容策略
人工智能·算法·机器学习·技术好geo优化
风栖柳白杨12 小时前
【面试】AI算法工程师_空白自测版本
人工智能·算法·面试
闪电悠米13 小时前
力扣hot100-73.矩阵置零-标记数组详解
算法·leetcode·矩阵
栋***t13 小时前
从“纸质试卷”到“AI智能组卷”,麦塔在线考试系统如何重构出题逻辑?
java·大数据·人工智能·算法·重构