【无标题】

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.题目描述

解题思路

定义字符串实际是定义一个二维数组,然后定义将str[0]设为min,str[1]设为mid,str[2]设为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;
}
相关推荐
2501_940315261 天前
leetcode182动态口令(将字符的前几个元素放在字符串后面)
算法
老鼠只爱大米1 天前
LeetCode经典算法面试题 #98:验证二叉搜索树(递归法、迭代法等五种实现方案详解)
算法·leetcode·二叉树·递归·二叉搜索树·迭代
疯狂的喵1 天前
C++编译期多态实现
开发语言·c++·算法
scx201310041 天前
20260129LCA总结
算法·深度优先·图论
2301_765703141 天前
C++中的协程编程
开发语言·c++·算法
m0_748708051 天前
实时数据压缩库
开发语言·c++·算法
小魏每天都学习1 天前
【算法——c/c++]
c语言·c++·算法
智码未来学堂1 天前
探秘 C 语言算法之枚举:解锁解题新思路
c语言·数据结构·算法
Halo_tjn1 天前
基于封装的专项 知识点
java·前端·python·算法
春日见1 天前
如何避免代码冲突,拉取分支
linux·人工智能·算法·机器学习·自动驾驶