- 论坛徽章:
- 0
|
回复 61# 叼着馒头看电视
失望了,
这是我在47楼发的,希望你可以帮我检查一下,告诉我对不对- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char **argv)
- {
- int w, q, i, k;
- if (argc < 2) {
- fprintf(stderr, "Usage: %s w ...", argv[0]);
- exit(0);
- }
- for (i = 1; i < argc; i++) {
- printf("%s: ", argv[i]);
- w = atoi(argv[i]);
- for (k = 0; w > 0 || (w%7 && w%5); k++)
- w -= 12;
- if (w == 0)
- printf("(12)*%d\n", k);
- else if (w%7 == 0) {
- q = w/7 >= 0 ? w/7 : -w/7;
- if (q > k)
- printf("(-7)*%d + (5)*%d\n", q-k, k);
- else if (q == k)
- printf("(5)*%d\n", q);
- else
- printf("(5)*%d + (12)*%d\n", q, k-q);
- }
- else if (w%5 == 0) {
- q = w/5 >= 0 ? w/5 : -w/5;
- if (q > k)
- printf("(-5)*%d + (7)*%d\n", q-k, k);
- else if (q == k)
- printf("(7)*%d\n", q);
- else
- printf("(7)*%d + (12)*%d\n", q, k-q);
- }
- }
- }
复制代码 |
|