【无标题】

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;
}
相关推荐
这料鬼有毒17 小时前
二刷hot100-17.电话号码的字母组合
数据结构
执明wa17 小时前
从 T 到协变逆变
java·开发语言·数据结构
阿Y加油吧17 小时前
两道数组算法题复盘:多数元素 & 颜色分类
算法·leetcode·职场和发展
夏日听雨眠17 小时前
排序(选择排序 ,冒泡排序,归并排序)
数据结构·算法·排序算法
tyung18 小时前
Go 手写二叉堆优先队列:避开 container/heap 的性能陷阱
数据结构·后端·go
珠海西格电力18 小时前
零碳园区的能源成本优势具体体现在哪些方面
大数据·人工智能·算法·架构·能源
Donk_6718 小时前
Shell 数组实践
linux·算法·bash
papership18 小时前
【入门级-数据结构-1、线性结构:栈和队列】
数据结构
fu的博客18 小时前
【数据结构14】并查集:QuickUnion、QuickFind、路径压缩
数据结构
比特森林探险记18 小时前
底层数据结构分析 go 语言中的 slice map channel interface
数据结构·golang·哈希算法