12.2训练心得
程序员文章站
2023-10-27 22:54:10
题目 | Stat | Origin | Title | Problem Title | | | | | | | Solved | A | "HDU 1161" | " Eddy's mistakes" | | Solved | B | "HDU 1406" | " 完数" | | Solved | ......
题目
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题
这道题其实不想让我这个菜鸡过的,但是这道题有个巧妙方法完美避开了使用快速幂算法,那就是万能无敌的找规律
上一篇: Python的print的底层实现