题目大意:中文
注释代码:
/*
* Problem ID : NPOJ 1065 喵星人吃土豆
* Author : Lirx.t.Una
* Language : C
* Run Time : 14
* Run Memory : 1092
*/
#include <stdio.h>
//数字的最大位数(最后一位留给'\0')
#define MAXLEN 1000
//num[i]表示数字i对应的火柴棒的数量
char num[10] = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
char sx[MAXLEN];//string x,表示数字x的字符串
int
main() {
int t;//测例数
int iscn;
int ans;//最终火柴棒的数量
int i;//计数变量
char * x;//偏移指针
scanf("%d", &t);
iscn = 0;
while ( t-- ) {
scanf("%s", sx);
x = sx;
printf("Case #%d: ", ++iscn);
while ( *x && '0' == *x ) x++;//忽略前导0
if ( !*x ) { puts("6"); continue; }//如果直接是0则输出0的火柴棒数6
ans = 0;
while ( *x ) ans += (int)num[ *(x++) - '0' ];//否则就计算前导0后面的火柴棒书
printf("%d\n", ans);
}
return 0;
}
无注释代码:
#include <stdio.h>
#define MAXLEN 1000
char num[10] = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
char sx[MAXLEN];
int
main() {
int t;
int iscn;
int ans;
int i;
char * x;
scanf("%d", &t);
iscn = 0;
while ( t-- ) {
scanf("%s", sx);
x = sx;
printf("Case #%d: ", ++iscn);
while ( *x && '0' == *x ) x++;
if ( !*x ) { puts("6"); continue; }
ans = 0;
while ( *x ) ans += (int)num[ *(x++) - '0' ];
printf("%d\n", ans);
}
return 0;
}