---
title: "PAT 1005 Spell It Right"
author: "J2EE大鸟"
date: "2013-03-02T12:07:59Z"
tags: []
categories: ["编程语言"]
slug: "pat-1005-spell-it-right"
draft: false
lastmod: "2013-03-02T12:07:59Z"
id: 1820111
url: "https://benworld.iteye.com/blog/1820111"
---

![](http://dl.iteye.com/upload/attachment/0081/0546/b7e47be7-c44f-3dd3-9e53-ae084fde6a48.jpg)  
 

```
#include "stdio.h"
#include "string.h"

#define N 10
#define M 102

int main(){
	char *p[N]={"zero","one","two","three","four","five","six","seven","eight","nine"};
	char num[M];
	int i,j,t,sum,a[5],b[5];
	while(scanf("%s", &num) != EOF && strlen(num)<=101){
		sum = 0;
		for(i=0;i<strlen(num);i++){
			sum += num[i] - '0';
		}
		j=0;
		if(sum == 0) {
			printf("%s", p[sum]);
		} else {
			while(sum!=0){
				a[j] = sum%10;
				sum /= 10;
				j++;
			}
		
			for(t=j-1;t>=0;t--){
				if(t != j-1) printf(" ");
				printf("%s", p[a[t]]);
			}
		}
		
	}
	return 0;
}
```