3.28学习总结

完成分割回文串的算法题,难点主要在如何去分割,靠什么去分割字符串

复制代码
int a(char arr[]){
    int i,j;
    int len=strlen(arr);
    for(i=0,j=len-1;i<j;i++,j--){
        if(arr[i]!=arr[j]) return 0;
    }
    return 1;
 }
 char **path;
 int pathtop;
 char***reasult;
 int*ansize;
 int count;
 void copy(){
    char**tempth=(char**)malloc(sizeof(char*)*pathtop);
    int i;
    for(i=0;i<pathtop;i++){
        tempth[i]=path[i];
    }
    reasult[count]=tempth;
    ansize[count++]=pathtop;
 }
 char*cutstring(char*str,int startindex,int endindex){
    char*temp=(char*)malloc(sizeof(char)*(endindex-startindex+2));
    int i;
    int index=0;
    for(i=startindex;i<=endindex;i++){
        temp[index++]=str[i];
    }
    temp[index]='\0';
    return temp;
 }
 void backtracking(char*s,int startindex,int size){
    if(startindex>=size){
      copy();
      return;
    }
    for(int i=startindex;i<size;i++){
        char*temp=cutstring(s,startindex,i);
        if(a(temp)){
            path[pathtop++]=temp;
        }else {
            continue;
        }
        backtracking(s,i+1,size);
        pathtop--;
    }
 }
char*** partition(char* s, int* returnSize, int** returnColumnSizes){
             int len=strlen(s);
             char*** partition(char* s, int* returnSize, int** returnColumnSizes);
             path=(char**)malloc(sizeof(char*)*len);
             reasult=(char***)malloc(sizeof(char**)*40000);
             ansize=(int*)malloc(sizeof(int)*40000);
             pathtop=0;
             count=0;
             backtracking(s,0,len);
             *returnSize=count;
             *returnColumnSizes=(int*)malloc(sizeof(int)*(*returnSize));
             for(int i=0;i<*returnSize;i++){
                (*returnColumnSizes)[i]=ansize[i];
             }
             return reasult;
}

继续跟着写Java的拼图小游戏的项目,感觉对Java的使用更清晰了

相关推荐
Mr.Jessy18 小时前
JavaScript高级:构造函数与原型
开发语言·前端·javascript·学习·ecmascript
fie88891 天前
NSCT(非下采样轮廓波变换)的分解和重建程序
算法
玄斎1 天前
MySQL 单表操作通关指南:建库 / 建表 / 插入 / 增删改查
运维·服务器·数据库·学习·程序人生·mysql·oracle
晨晖21 天前
单链表逆转,c语言
c语言·数据结构·算法
im_AMBER1 天前
Leetcode 78 识别数组中的最大异常值 | 镜像对之间最小绝对距离
笔记·学习·算法·leetcode
鼾声鼾语1 天前
matlab的ros2发布的消息,局域网内其他设备收不到情况吗?但是matlab可以订阅其他局域网的ros2发布的消息(问题总结)
开发语言·人工智能·深度学习·算法·matlab·isaaclab
其美杰布-富贵-李1 天前
HDF5文件学习笔记
数据结构·笔记·学习
LYFlied1 天前
【每日算法】LeetCode 25. K 个一组翻转链表
算法·leetcode·链表
Swizard1 天前
别再迷信“准确率”了!一文读懂 AI 图像分割的黄金标尺 —— Dice 系数
python·算法·训练
s09071361 天前
紧凑型3D成像声纳实现路径
算法·3d·声呐·前视多波束