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的使用更清晰了

相关推荐
奶茶精Gaaa33 分钟前
工具分享--json在线转换工具
学习
爱敲代码的TOM39 分钟前
数据结构总结
数据结构
CoderCodingNo1 小时前
【GESP】C++五级练习题 luogu-P1865 A % B Problem
开发语言·c++·算法
wdfk_prog1 小时前
[Linux]学习笔记系列 -- [drivers][I2C]I2C
linux·笔记·学习
大闲在人1 小时前
7. 供应链与制造过程术语:“周期时间”
算法·供应链管理·智能制造·工业工程
盐焗西兰花1 小时前
鸿蒙学习实战之路-Reader Kit自定义字体最佳实践
学习·华为·harmonyos
小熳芋1 小时前
443. 压缩字符串-python-双指针
算法
Charlie_lll1 小时前
力扣解题-移动零
后端·算法·leetcode
chaser&upper1 小时前
矩阵革命:在 AtomGit 解码 CANN ops-nn 如何构建 AIGC 的“线性基石”
程序人生·算法
weixin_499771551 小时前
C++中的组合模式
开发语言·c++·算法