这个题目明显用数组比用switch简单
----------------解决方案--------------------------------------------------------
#include<stdio.h>
void main()
{
char a[10][10]={"zero","one","tow","tree","four","five","six","seven","eght","nine"};
int i;
char b[10];
while(scanf("%s",b)!=EOF)
{
for(i=0;b[i];i++)
printf("%s ",a[b[i]-'0']);
printf("\n");
}
}
----------------解决方案--------------------------------------------------------
用指针,或者数组,加个switch就可以了,呵呵好心都搞定了啊。
----------------解决方案--------------------------------------------------------
crackerwang
一直拉下来看,终于看到一个是这样做的.
----------------解决方案--------------------------------------------------------
我改了以下你的代码
#include<stdio.h>
void main()
{
char a[10][10]={"zero","one","tow","tree","four","five","six","seven","eght","nine"};
int i;
while(scanf("%1d",&i)!=EOF)
{
printf("%s ",a[i]);
}
}
----------------解决方案--------------------------------------------------------
mp3改的好简洁,佩服
----------------解决方案--------------------------------------------------------
厉害.
我怎么就没有想到呢?
高手就是高手
----------------解决方案--------------------------------------------------------
以下是引用mp3aaa在2007-4-17 21:59:40的发言:
我改了以下你的代码
#include<stdio.h>
void main()
{
char a[10][10]={"zero","one","tow","tree","four","five","six","seven","eght","nine"};
int i;
while(scanf("%1d",&i)!=EOF)
{
printf("%s ",a[i]);
}
}
#include<stdio.h>
void main()
{
char a[10][10]={"zero","one","tow","tree","four","five","six","seven","eght","nine"};
char c;
while((c=getchar())!='\0')
{
printf("%s ",a[c-'0']);
}
}
----------------解决方案--------------------------------------------------------
呵呵nuciewth斑竹 scanf("%1d",&i) 我这里用的是 1d 也就是说每次有只有1位数存入i
----------------解决方案--------------------------------------------------------
斑竹看错了估计看成了ld了 long int
哈哈
ld
1d
谁能用眼睛分的清楚
----------------解决方案--------------------------------------------------------