• 蓝桥练习部分题


    5顺时针螺旋数:

    #include<stdio.h>
    #include<string.h>
    
    int map[25][25];
    
    int main()
    {
        int n;
        while(scanf("%d", &n) != EOF)
        {
            memset(map, 0, sizeof(25));
            int temp = 1;
            int x , y;
            int up = 1, down = n;
            int left = 1, right = n;
            while(temp <= n*n)
            {
                for(int i = left; i <= right; i++)
                {
                    map[up][i] = temp++;
                }
                up++;
    
                for(int i = up; i <= down; i++)
                {
                    map[i][right] = temp++;
                }
                right--;
    
                for(int i = right; i >= left; i--)
                {
                    map[down][i] = temp++;
                }
                down--;
    
                for(int i = down; i >= up; i--)
                {
                    map[i][left] = temp++;
                }
                left++;
            }
    
            for(int i = 1; i <= n; i++)
            {
                for(int j = 1; j <= n; j++)
                {
                    printf("%d ", map[i][j]);
                }
                printf("\n");
            }
        }
        return 0;
    }
    

    6.从键盘输入一个日期,格式 yyyy-M-d,要求计算该日期与 1949 年 10月 1 日距离多少天

    例如 :

    1949-10-2

    1

    1949-11-1

    2

    #include<stdio.h>
    int ms[13] = {0,31,28,31,30,31,30,31,30,31,31,30,31,30,31};
    int main()
    {
        int year, month, day;
        char c1, c2;
        while(scanf("%d%c%d%c%d",&year, &c1, &month, &c2, &day) != EOF)
        {
            int ans = 0;
    
            if(y == 1949)
            {
                for(int i = 10; i < month; i++)
                    ans += ms[i];
                ans += day;
                ans--;
            }
            else
            {
                ans += ms[10]+ms[11]+ms[12]-1; //1949
                for(int y = 1950; y < year; y++) //1949----year-1
                {
                    if((y%4==0 && y%100 != 0) || y%400 == 0) ans += 366; //ÈóÄê
                    else ans += 365; //ƽÄê
                }
    
                for(int m = 1; m < month; m++) //1----month-1
                {
                    ans += ms[i];
                }
    
                ans += day;
                if((year%4==0 && year%100 !=0) || year%400==0)
                {
                    if(month > 2) ans++;
                }
    
    
            }
            printf("%d\n", ans);
    
        }
        return 0;
    }
    

    7信用卡卡号检测

    #include<stdio.h>
    #include<string.h>
    
    int a[100];
    char str[100];
    int main()
    {
        while(scanf("%s", str))
        {
            int len = strlen(str);
            int j = 1;
            for(int i = len-1; i >= 0; i--)
            {
                a[j++] = str[i]-'0';
            }
    
            int odd = 0; //奇数
            int even = 0;
            for(int i = 1; i <= len; i++)
            {
                if(i%2 == 0)
                {
                    even += a[i]*2 >= 10 ? a[i]*2-9 : a[i]*2;
                }
                else odd += a[i];
            }
    
            if((odd+even) % 10 == 0) printf("成功\n");
            else printf("失败\n");
        }
        return 0;
    }
    


    13平方的末位为本身【效率较低】

    #include<stdio.h>
    int main()
    {
        for(int i = 100; i < 10000; i++)
        {
            if(i*i%1000 == i) printf("%d\n", i);
        }
        return 0;
    }

    14.概率【结果好像有点问题】
    #include<stdio.h>
    #include<math.h>
    int main()
    {
        int total = 2*2*2*2;
        double n = 0;
        double a = 1000;
        double b = 2000;
        for(int i = 0; i <=1; i++)
        {
            if(i == 0)
            {
                a += b/4;
                b = b/4*3;
            }
            else
            {
                b += a/4;
                a = a/4*3;
            }
            for(int j = 0; j <= 1; j++)
            {
                if(j == 0)
                {
                    a += b/4;
                    b = b/4*3;
                }
                else
                {
                    b += a/4;
                    a = a/4*3;
                }
    
                for(int k = 0; k <= 1; k++)
                {
                    if(k == 0)
                    {
                        a += b/4;
                        b = b/4*3;
                    }
                    else
                    {
                        b += a/4;
                        a = a/4*3;
                    }
                    for(int e = 0; e <= 1; e++)
                    {
                        if(e == 0)
                        {
                            a += b/4;
                            b = b/4*3;
                        }
                        else
                        {
                            b += a/4;
                            a = a/4*3;
                        }
                        if((b-a<1000 && b-a>0) || (a-b<1000 && a-b>0)) n++;
                        //printf("%d %d %d %d %lf %lf\n", i, j, k, e, a, b);
                        //printf("%lf \n", a-b);
                    }
                }
            }
        }
        //printf("%lf\n", n);
        printf("%.3lf\n",(double)n/16.0);
        return 0;
    }
    

    15打印整数的划分

    #include<stdio.h>
    
    int n, cnt;
    int a[21];
    
    void fun(int divi, int sum)
    {
        if(sum == n) //注意最后一位的输出
        {
            for(int i = 0; i < cnt-1; i++)
                printf("%d+", a[i]);
            if(n-a[0] == cnt-1) printf("%d\n", a[cnt-1]);
            else printf("%d,", a[cnt-1]);
            return;
        }
    
        for(int i = divi; i > 0; i--) //由大到小划分
        {
            if(sum+i <= n)
            {
                a[cnt++] = i;
                fun(i, sum+i); //划分 i,而不是 n-i,因为打印的结果是由大到小排序的
                               //所以每次枚举的最大数不能超过上次的最大值,同时也避免了重复
                cnt--; //回溯,划分比i小1的
            }
        }
    }
    int main()
    {
        while(scanf("%d", &n) != EOF)
        {
            cnt = 0;
            fun(n, 0);
        }
        return 0;
    }
    
    /*
    //递归种数
    #include<stdio.h>
    
    int q(int n, int m)
    {
        if(n < 1 || m < 1) return 0;
        if(n==1 || m==1)
            return 1;
        if(n < m)
            return q(n, n);
        if(n == m)
            return q(n, m-1)+1;
        return q(n, m-1)+q(n-m,m);
    }
    int main()
    {
        int n;
        while(scanf("%d", &n) != EOF)
        {
            int ans = q(n,n);
            printf("%d\n", ans);
        }
        return 0;
    }
    */
    

    16.21位花朵数,不会做点击打开链接

  • 相关阅读:
    web项目中添加logger日志
    oracle 创建表空间
    从request中读数据流
    通过request获取ID地址的方法
    创建表空间的sql语句
    plsql点击不再提示后需重新提示
    js文件报错Syntax error on token "Invalid Regular Expression Options", no accurate correction
    java知识
    DevC++出现[Error] ld returned 1 exit status,如何解决才好呢?
    1
  • 原文地址:https://www.cnblogs.com/freezhan/p/3219100.html
Copyright © 2020-2023  润新知