当前位置: 移动技术网 > IT编程>开发语言>C/C++ > 12.2训练心得

12.2训练心得

2018年12月04日  | 移动技术网IT编程  | 我要评论

es60h-z4,你好陌生人迅雷下载,西安上门按摩

题目

stat origin title problem title
solved a hdu 1161 eddy's mistakes
solved b hdu 1406
solved c hdu 1097 a hard puzzle
solved d hdu 1001 sum problem
solved e hdu 1019 least common multiple
solved f hdu 1108
solved g hdu 1008 elevator

a题

​ 没什么难度了,用的ctype里面的tolower函数遍历一遍就解决了

ac代码:

#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main()
{
    char a[1000+100];
    int i;

    while(gets(a) != null)
    {
        for( i = 0; i < strlen(a); i++)
        {
            if( a[i] >= 'a' && a[i] <= 'z')
                a[i] = tolower(a[i]);
        }
        puts(a);
    }
    return 0;
}

b题

​ 其实也没什么难度,为了减少时间复杂度,用了math的sqrt函数,然后再取模判断就ok了,有一个小坑点,就是输入的m,n没有固定大小顺序,也许先输入的比后输入的大。

ac代码:

#include<stdio.h>
#include<math.h>

int main()
{
    int t;
    int m, n;
    int i, j;
    int temp;

    scanf("%d", &t);
    while(t--)
    {
        scanf("%d%d", &m, &n);
        if( m > n)
        {
            temp = m;
            m = n;
            n = temp;
        }
        int count = 0;
        for( i = m; i <= n; i++)
        {
            int sum = 1;
            for( j = 2; j <= sqrt(i); j++)
            {
                if( i % j == 0)
                {
                    sum += j + i/j;
                    if( j == i/j)
                        sum -= i/j;
                }
            }
            if( sum == i)
                count++;
        }
        printf("%d\n", count);
    }
    return 0;
}

c题

​ 这道题其实不想让我这个菜鸡过的,但是这道题有个巧妙方法完美避开了使用快速幂算法,那就是万能无敌的找规律

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网