zoukankan      html  css  js  c++  java
  • 几个经典题目

    'A'-65 'Z'-90

    'a'-97 'z'-122

    '0'-48 '9'-57

    约瑟夫环

    #include<stdio.h>
    #include<conio.h>
    #define N 100
    int main(){
        int m;
        int n;
        printf("请输入总人数n 
    ");
        scanf("%d",&n);
        printf("请输入报的数m 
    ");
        scanf("%d",&m);
        int a[N] = {0};
        int i;
        int j;
        int k = 0;
        for(i = 0; i < n; i++){
            a[i] = i+1;
        }
        while (n > 1){
            i = (i + m - 1) % n;
            k++;
            printf("第%d个出圈的是%d
    ",k,a[i]);
            for(j = i+1; j < n; j++){
                a[j-1] = a[j];
            }
            n--;
            if(i == n){
                i = 0;
            }
        }
        printf("最后剩下的时%d
    ", a[i]);
        return 0;
    }

    最长回文子串

    #include <stdio.h>
    #include <string.h>
    #include <stdbool.h>
    char* longestpalindrome(const char *str){
        bool dp[100][100];
        int i,j,len;
        int longest = 1;//最长子串的长度
        int tmp;
        int n = strlen(str);
        char a[n];//最长子串存放位置
        for(i = 0; i < n; i++){
            dp[i][i] = 1;
            if(str[i] == str[i + 1]){
                dp[i][i + 1] = 1;
                longest = 2;
                strncpy(a,str + i,2);
            }
        }
        for(len = 3; len <= n; len++){
            for(i = 0; i <= n - len; i++){
                j = i + len - 1;
                if(str[i] == str[j]){
                    dp[i][j] = dp[i + 1][j - 1];
                    if(dp[i][j] == 1){
                        tmp = j - i + 1;
                        if(longest < tmp){
                            longest = tmp;
                            strncpy(a,str + i,tmp);
                        }
                    }
                }
                else
                    dp[i][j] = 0;
            }
        }
        printf("%d
    ",longest);
        char *s = a;       
        return s;
    }
    
    int main(){
        char a[20];
        scanf("%s",a);
        char *s = longestpalindrome(a);
        printf("%s
    ",s);
        return 0; 
    }

     最大回文子串简单算法(循环就完事了)

    #include<stdio.h>
    #include<conio.h>
    #include<string.h>
    void Max(char *str){
        int len,i,j; 
        len=strlen(str);
        int maxlen=1;
        int start=0;
        for(i=0;i<len;i++){
            for(j=i+1;j<len;j++){
                int flag1=i,flag2=j;
                while(flag1<flag2&&str[flag1]==str[flag2]){
                    flag1++;
                    flag2--;
                }
                if(flag1>=flag2&&j-i+1>maxlen){
                    maxlen=j-i+1;
                    start=i;
                }
            }
        }
        for(i=start;i<start+maxlen;i++){
            printf("%c",str[i]);
        }
    }
    int main(){
        char str[100];
        scanf("%s",str);
        Max(str);
        return 0;
    }
  • 相关阅读:
    Effective java ---遵守普遍接受的命名规则
    slf4j(后面总结)
    jQuery ajax
    JS面向对象、prototype、call()、apply()
    为什么实例没有prototype属性?什么时候对象会有prototype属性呢?
    JavaScript prototype 使用介绍
    深入javascript——构造函数和原型对象
    Javascript中String、Array常用方法介绍
    JS中如何得到触发事件的属性?
    jquery操作复选框(checkbox)的12个小技巧总结
  • 原文地址:https://www.cnblogs.com/jackliu-timecomplexity/p/10645712.html
Copyright © 2011-2022 走看看