急!急!急! 小弟遇见一个难题。请高手帮忙。是把数字换文字输入,在线等。

gztan 2006-03-13 08:33:52
一个函数fun(inputdata),数字转换函数,例如输入inputdata=88008.88
输入fun="八万八千八零八点八八"
...全文
238 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
covsno 2006-03-14
  • 打赏
  • 举报
回复
#include <string.h>
#include <iostream.h>
#include <stdlib.h>
void main()
{
char input[16] = "123.4";
char *p;
p = strtok(input, ".");
char* cWei[] = {"零","十","百"};
char* cNum[] = {"一","二","三","四"};
int len=strlen(p);
while(len)
{
cout<<cNum[*(p)-'1']<<cWei[len-1];
p++;
len--;
}
cout<<"点";
p = strtok(NULL, ".");
len=strlen(p);
while(len)
{
cout<<cNum[*(p)-'1']<<cWei[len-1];
p++;
len--;
}

}
covsno 2006-03-14
  • 打赏
  • 举报
回复
char input[16] = "123.4";
char *p;
p = strtok(input, ".");/*p="123"*/
char cWei[] = {"零","拾","佰"};//类似的
char cNum[] = {"一","二","三","四"};//等等
int len=strlen(p);
while(p)
cout<<cNum[atoi(*(p++))]<<cWei[len--];
cout<<"点";
p = strtok(NULL, ".");
len=strlen(p);
while(p)
cout<<cNum[atoi(*(p++))];
king_fp 2006-03-13
  • 打赏
  • 举报
回复
我以为上上面的大哥一下就写出来了,....
ouyh12345 2006-03-13
  • 打赏
  • 举报
回复
小数点后的不管。
小数点前的大致可这样做:
char cWei[] = {"零","拾","佰"};//类似的
char cNum[] = {"壹","贰"};//等等

void fun(int input)
{
while(input / 10 != 0)
{
//取余和位数
//根据余和位数构造字符串
input = input / 10;
}
}
gztan 2006-03-13
  • 打赏
  • 举报
回复
有详细的代码吗。
这样我才知道怎么做啊。
PMsg 2006-03-13
  • 打赏
  • 举报
回复
取余数然后替换
covsno 2006-03-13
  • 打赏
  • 举报
回复
他又没有说输入一定是double的
lonelyforest 2006-03-13
  • 打赏
  • 举报
回复
有空看看人民币大小写转换程序就行了, 简直就是那东西!
Ninstein 2006-03-13
  • 打赏
  • 举报
回复
能处理带小数点的
http://topic.csdn.net/t/20010911/13/281869.html


有时候 搜索也是一种艺术
逸学堂 2006-03-13
  • 打赏
  • 举报
回复
搜索以前的文章,前边有人问过了。
Ninstein 2006-03-13
  • 打赏
  • 举报
回复
#include"stdlib.h"
#include"string.h"


typedef struct snode{
char data1[4];
char data2[5];
struct snode *next;
}node;
char number[10][3]={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
char unit[6][5]={"圆整","拾","佰","仟","万","亿"};
int i=0;
node *link(long n,node *s)
{int d;int t;
node *p;
node *new;
new=(node *)malloc(sizeof(node));
d=n%10;
n=n/10;
strcpy(new->data1,number[d]);
if(i==9)t=i-8;
else if(i==8)t=5;
else if(i<8&&i>4)t=i-4;
else t=i;
strcpy(new->data2,unit[t]);
new->next=NULL;
i++;
if(n!=0)s=link(n,s);
if(s==NULL)s=new;
else {
p=s;
while(p->next!=NULL)
p=p->next;
p->next=new;
}
return s;
}
node *judge(node *s)
{node *p,*q;
p=s;
while(p!=NULL)
{if(strcmp(p->data1,"零")==0)
while(strcmp(p->next->data1,"零")==0)
{q=p->next;
p->next=q->next;
free(q);
}
p=p->next;
}
return s;
}
void dispstr(node *s)
{if(s==NULL)
printf("空串");
else{while(s!=NULL)
{ if(strcmp(s->data2,"亿")==0&&strcmp(s->next->next->data2,"仟")==0)
{printf("%s%s",s->data1,unit[5]);
s=s->next;
}
else if(strcmp(s->data1,"零")==0&&s->next==NULL)
{printf("%s",unit[0]);
break;
}
else if(strcmp(s->data1,"零")==0&&strcmp(s->next->data2,"仟")==0&&strcmp(s->data2,"亿")!=0)
printf("%s",unit[4]);
else if(strcmp(s->data1,"零")==0&&strcmp(s->data2,"亿")==0)
printf("%s",unit[5]);
else printf("%s",s->data1);
if(strcmp(s->data1,"零")!=0)
printf("%s",s->data2);
s=s->next;
}
}


}
void Nfree(node *s)
{node *p;
while (s!=NULL)
{p=s;
s=s->next;
free(p);
}
}
void main()
{long n;
node *s=NULL;
clrscr();
printf("please input a number n:");
scanf("%ld",&n);
s=link(n,s);
s=judge(s);
dispstr(s);
Nfree(s);
printf(" ");
}
baggio1984 2006-03-13
  • 打赏
  • 举报
回复
我们老师让我们做过,不过是c#的,整数可以用取余,小数部分不能用

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧