看板 C_and_CPP 關於我們 聯絡資訊
這題還蠻簡單的呀,隨便寫了一個就過了 :) #include <stdio.h> char ResultPerfect[] = {"PERFECT"}; char ResultDeficient[] = {"DEFICIENT"}; char ResultAbundant[] = {"ABUNDANT"}; char *CheckResult(int Value) { int start, sum = 0; for (start = 1; start < Value; start++) sum += (0 == (Value % start) ? start : 0); if (sum == Value) return ResultPerfect; if (sum < Value) return ResultDeficient; return ResultAbundant; } int main(int argc, char *argv[]) { int i, buf[100]; for (i = 0; 1 == scanf("%d", &buf[i]); i++) if (0 == buf[i]) break; printf("PERFECTION OUTPUT\n"); for (i = 0; 0 != buf[i]; i++) printf("%*d %s\n", 5, buf[i], CheckResult(buf[i])); printf("END OF OUTPUT\n"); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.128.220.49