【練習】PTA A1005 Spell It Right

兩個測試用例不能通過,還沒找到問題。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char num[10][7]={"zero","one","two","three","four","five","six","seven","eight","nine"};

int main(){
	int NUM,n=0,m=0,s=0;
	int sum[111],c[111];
	scanf("%d",&NUM);
	while(NUM!=0){
	sum[n++]=NUM%10;
	NUM/=10;
	}
	for(int i=0;i<n;i++){
		s+=sum[i];
	}
	if(s==0) printf("%s",num[0]);
	else{
		while(s!=0){
		c[m++]=s%10;
		s/=10;
		}
		for(int i=m-1;i>=0;i--){
			printf("%s",num[c[i]]);
			if(i!=0){
				printf(" ");
			}
		}
	}
	system("pause");
    return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章