一个银行面试题目?(初学者)

xiejiaohui 2001-12-18 06:08:20
用C 语言实现大小写的转换,哪个的最短,最精简分全给她(他)
eg: 100009.54 ------ 十万零九元五角四分整
...全文
330 37 打赏 收藏 转发到动态 举报
写回复
用AI写文章
37 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiejiaohui 2002-01-22
  • 打赏
  • 举报
回复
fgvhbgf
xiejiaohui 2002-01-22
  • 打赏
  • 举报
回复
结贴
xiejiaohui 2002-01-22
  • 打赏
  • 举报
回复
zxcxvvxc
chehw 2002-01-03
  • 打赏
  • 举报
回复
#include <stdlib.h>
#include <string.h>

int DigitalToUpper(double digital, int iBitsAfterDigitalDot,char *szDisplay)
{
static char *szUnit[]={"点","","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟","万","亿","拾","佰","仟","万"};
static char *szDig[]={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
int iDotPosition=0,fSigned=0;//小数点位置和正负号判断
char *szDigital=_fcvt(digital,iBitsAfterDigitalDot,&iDotPosition,&fSigned);//将double类型转为String
char *p=szDisplay;
*p=0;
if(fSigned) strcpy(p,"负");
int i=0;
int iDig;
int fHideZero=0;
if(iDotPosition==0) {
strcpy(p,"零");
}

while(szDigital[i])
{
iDig=szDigital[i]-0x30;//get the digit value
if(iDotPosition-i==0) strcat(p,szUnit[0]);
if(iDig==0)
{
if(iDotPosition-i>0) fHideZero=1;
else strcat(p,szDig[0]);
}
else{
if(fHideZero&&(iDotPosition-i>0) ) strcat(p,szDig[0]);

strcat(p,szDig[iDig]);
if(iDotPosition-i>0) {
strcat(p,szUnit[iDotPosition-i]);
}
fHideZero=0;
}
i++;
}

return 1;
}


int main(int argc, char* argv[])
{
int iBitsAfterDigitalDot=2; // 小数点位数过大会影响精度,此处暂设为2
double dw;//待输入数据
while(1)
{
printf("\n请输入待转换的数字:(-1 To Exit)\n");
scanf("%lf",&dw);
if(dw==-1.0) break;
printf("小数点位数=:(default=2)\n");
scanf("%d",&iBitsAfterDigitalDot);
printf("\n");
char szDisplay[100];//
DigitalToUpper(dw,iBitsAfterDigitalDot,szDisplay); // the Utility Function

char szFmt[100];//
sprintf(szFmt,"%%.%df\n",iBitsAfterDigitalDot);

printf("输出格式为: %s",szFmt);
printf("小写 = ");
printf(szFmt,dw);
printf("\n大写 = %s\n",szDisplay);
}

return 0;
}

U_U 2002-01-02
  • 打赏
  • 举报
回复
我回家写了一个这样的程序,用了一天,还没有编译,明天编译好了,再打上来,用了80多行代码.
xiejiaohui 2002-01-02
  • 打赏
  • 举报
回复
祝大家:马到成功:

.............."$$$$$$$$$o.........ooo$$$$$$$$$
.......ooo$$$$$$$$$$$$$$$....oo$$$$$$$$$$$"""
.......$$$$$$$$$$$$$$$$o....o$$$$$$$"""
.........$$$$$$$"""o$$$$$$...$$$$$$
..........$$$$$$..o$$$$$"....$$$$$
..........$$$$$$.o$$$$$".....$$$$$.....ooo.oo$$$o
...........$$$$$$$$$$$$$$...$$$$$"...o$$$$$$$$$$$$
.........oo$$$$$$$$$$$""....$$$$$$$$$$$$$$$$$$$$$$
........."$$$$$$$$$$$ooo....$$$$$$$$$$$$$$$$"
..........."""$$$$$$$$$$$o..$$$$$$$$$$$$$$$$
...........oo$$$$$$$$$$$$"..$$$$.....$$$$$$$
......oo$$$$$$$$$$$$$""....o$$$$.....$$$$$$$
.....$$$$$$$$$$$$$$$$oooo..$$$$$.....$$$$$$$
.....$$$$$$$"."$$$$$$$$$$$$$$$$".....$$$$$$$
......""$$$....$$$$$$."$$$$$$$$......$$$$$$$
........$$$o..$$$$$$$......$$$$......$$$$$$$
......."$$$"oo$$$$$$$......$$$"......$$$$$$$
............$$$$$$$$"......""........$$$$$$"
.............""""....................$$$$$"
.....................................$$$$"
.....................................$$"
....................o$$$o......ooo$$$oo
..................o$$$$$$$oo$$$$$$$$$$$o
................o$$$$$$$$$$$$$$$$$$$$$$$
..............o$$$$$$"""$$$$$$$$$$$""
...........o$$$$$"".......""$$$$$$"
..........o$""".............$$$$$$ooo
......................ooooo$$$$$$$$$$$o
.....................$$$$$$$$$$$$$$$$$$
.....................$$$$$$$$$$$$$$"""
......................"""""$$$$$$$
................o$$$o......$$$$$$$.ooooooooooo
................$$$$$$oooo$$$$$$$$$$$$$$$$$$$$$
............oooo$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
.......oo$$$$$$$$$$$$$$$$$$$$$$$$$""""""""""""
.....o$$$$$$$$$$$$$$""""...$$$$$$$
.....$$$$$$$$"""...........$$$$$$$
......"""""................$$$$$$$
...........................$$$$$$$
...........................$$$$$$$
...........................$$$$$$
...........................$$$$$"
............................$$$
...............oo..........."""
..............$$$$$o..........oooo
..............$$$$$$..........$$$$$o
.............o$$$$$..........o$$$$$$
.............$$$$$$..........$$$$$$$oooooo
.............$$$$$$.......ooo$$$$$$$$$$$$$$$o
.......$$o...$$$$$$$$o...$$$$$$$$$$$$$$$$$$$$
......$$$$...$$$$$$$$$..."$$$$$$$$$$$"$$$$$$"
.....o$$$$oo$$$$$$$$$......"$$$$$$"...$$$$$$
.....$$$$$$$$$$$$$$"........$$$$$"..o$$$$$"
.....$$$$$$.$$$$$..........$$$$$$$$$$$$$$$$$$$$oo
....."$$$$$.$$$$$.oooo$$$$$$$$$$$$$$$$$$$$$$$$$$$$
......""""..$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"
............$$$$$$$$$$$$$$$$$$$""""
............$$$$$.""""""$$$$$$"
............$$$$$......o$$$$$".....oo$$oo
............$$$$$.....o$$$$$"......$$$$$$$$o
............$$$$$....o$$$$$........"$$$$$$$$o
............$$$$$...o$$$$"...........$$$$$$$$
............$$$$$...$$$"..............$$$$$$$
.............$$$$...""................"$$$$$
............."$$"......................""""
.......................$$$$o
......................o$$$$$o.........oooo
..............o$$$....$$$$$$........o$$$$$o
.............$$$$$.$$$$$$$$$$$$$o.o$$$$$$"
............$$$$$"o$$$$$$$$$$$$$$$$$$$$"oo
...........$$$$...$$$$$$$$"$$$$$$$$$$"o$$$$o
........o$$$$$..oo$$$$$$$..$$$$$$$$$$o$$$$$
........$$$$$$$$$$$$$$$$$oo$$$$$$$$$$$$$"
........"$$$$$$$$$$$$$$$$$$$$$$$$.$$$$$$$o
............o$$$$$$$$$$$$""$$$$$$$$$$"$$$$$
...........o$$$$.o$$$$$$$oo$$$$$$$$$$$$$$$$
..........o$$$$$$$$$$$$$$$$$$$$$$$$$$"$$$$"
.........o$$$$$$$"""$$$$$$$$$$$$""...."""
.........."$$""....."$$"$$$$$$ooooooo$$$$$$$$o
...............ooooo$$$$$$$$$$$$$$$$$$$$$$$$$$o
.......ooo$$$$$$$$$$$$$$$$$$$$$$$$$$""""""""""
......o$$$$$$$$$$$$$$"""$$$$$$....o$$$$o
......."$$$$$"$$$$......$$$$$$...."$$$$$$o
.........""..$$$$$......$$$$$$.....$$$$$$$o
.............$$$$$.....o$$$$$$......$$$$$$$
............."$$"...ooo$$$$$$$.......$$$$"
...................$$$$$$$$$"........"""
aim2010 2001-12-31
  • 打赏
  • 举报
回复
提个现实的问题,0.54应该读成五角四分整吗?整是什么意思?银行不是这样读的吧。
liunux 2001-12-31
  • 打赏
  • 举报
回复
对了,什么函数用来得到一个浮点数的整数部分,又有什么函数得到这个浮点数的小数部分啊,记得象是有这些函数的,不过忘了,找也没有找着啊。谢谢,并新年快乐!
linning2570 2001-12-31
  • 打赏
  • 举报
回复

┬┴┬┌─ ●─┬─  │─┼─┐ ●├─┤○
┴┬┴├┬ ┌─┼─ │◎ │ │ ○└┬┘●
─┼─││ │ │  ││─┴─┴ ──┼──
●│○││ ┴─┼─  │○  ● / │ \
微星1234 2001-12-31
  • 打赏
  • 举报
回复
char* nToSZ(double fSource)
{
long CurrentNum=100000000;
while((!(long)fSource/CurrentNum)&&(CurrentNum!=0))
{
CurrentNum/=10;
}
if(!CurrentNum)
f123 2001-12-30
  • 打赏
  • 举报
回复
如果可以用CString类就好办了,先把数值转换成为字符。
eion 2001-12-30
  • 打赏
  • 举报
回复
可别小瞧了它——
可是花了我一个中午的时间
(我还以为半个小时或一个小时就能搞定的,
可被你害惨了)
eion 2001-12-30
  • 打赏
  • 举报
回复
看看这个,是dos程序,如果想改为汉字输出,你还得作如下变换
a,b,c,d,e,f,g……改为 个,万,亿,兆,京……(后面不会了)
A,B,C,D 改为:个,十,百,千
就万事大吉了

#include <string.h>
#define BOOL int
#define TRUE 1
#define FALSE 0
void ReadNumber(char* s,char* out)
{
static char read4[]={'a','b','c','d','e','f','g','h'};
static char read[4] ={'A','B','C','D'};
int len_s = strlen(s);

int point=0;
BOOL isZero=0;
for(int i=0;i<len_s;i++)
{
int site4 = (len_s-i-1)/4;
int site = (len_s-i-1)%4;

if( s[i]=='0' )
{
if( site==0 )
{
if( out[point-1]>read4[site4] ) continue;
out[point++] = read4[site4];
isZero = FALSE;
}
else isZero = TRUE;
}
else
{
if( isZero ) out[point++]='0';
out[point++] = s[i];
if( site==0 )
{
out[point++] = read4[site4];
}
else
{
out[point++] = read[site];
}
isZero = FALSE;
}
}
}
void Out(char *s)
{
for(unsigned int i=0;i<strlen(s);i++)
{
cout<<s[i];
if( s[i]>='a' ) cout<<' ';
}
cout<<endl;
}
void main()
{
char s[100]="120020010400101",ans[100];
memset(ans,0,100);
memset(s,0,100);
cout<<"Please input your number : "<<endl;
cin>>s;
cout<<"you inputs: ";
for(unsigned i=0;i<strlen(s);i++)
{
if((strlen(s)-i)%4==0 ) cout<<','; cout<<s[i];
}
cout<<endl<<"you get:"<<endl;
ReadNumber(s,ans);
Out(ans);
}
r_james 2001-12-30
  • 打赏
  • 举报
回复
我想这能容易读懂,我也有他的简化算法,但我想不容易读。
r_james 2001-12-28
  • 打赏
  • 举报
回复
call=call*100;
call=call*100+0.5; //call 为小写的数值;

int m10000_00=(int)(call/1000000);
int m01000_00=(int)(((int)call%1000000)/100000);
int m00100_00=(int)(((int)call%100000)/10000);
int m00010_00=(int)(((int)call%10000)/1000);
int m00001_00=(int)(((int)call%1000)/100);
int m00000_10=(int)(((int)call%100)/10);
int m00000_01=(int)(((int)call%10)/1);

CString sm10000_00;//各字符串为大写每位的植;
CString sm01000_00;
CString sm00100_00;
CString sm00010_00;
CString sm00001_00;
CString sm00000_10;
CString sm00000_01;
CString Yuan;
CString Ling;
Yuan="圆";
Ling="零";

switch(m10000_00)
{
case 0 : sm10000_00="";break;
case 1 : sm10000_00="壹万";break;
case 2 : sm10000_00="贰万";break;
case 3 : sm10000_00="叁万";break;
case 4 : sm10000_00="肆万";break;
case 5 : sm10000_00="伍万";break;
case 6 : sm10000_00="陆万";break;
case 7 : sm10000_00="柒万";break;
case 8 : sm10000_00="捌万";break;
case 9 : sm10000_00="玖万";break;
};
switch(m01000_00)
{
case 0 : sm01000_00="";break;
case 1 : sm01000_00="壹仟";break;
case 2 : sm01000_00="贰仟";break;
case 3 : sm01000_00="叁仟";break;
case 4 : sm01000_00="肆仟";break;
case 5 : sm01000_00="伍仟";break;
case 6 : sm01000_00="陆仟";break;
case 7 : sm01000_00="柒仟";break;
case 8 : sm01000_00="捌仟";break;
case 9 : sm01000_00="玖仟";break;
};
switch(m00100_00)
{
case 0 : sm00100_00="";break;
case 1 : sm00100_00="壹佰";break;
case 2 : sm00100_00="贰佰";break;
case 3 : sm00100_00="叁佰";break;
case 4 : sm00100_00="肆佰";break;
case 5 : sm00100_00="伍佰";break;
case 6 : sm00100_00="陆佰";break;
case 7 : sm00100_00="柒佰";break;
case 8 : sm00100_00="捌佰";break;
case 9 : sm00100_00="玖佰";break;
};
switch(m00010_00)
{
case 0 : sm00010_00="";break;
case 1 : sm00010_00="壹拾";break;
case 2 : sm00010_00="贰拾";break;
case 3 : sm00010_00="叁拾";break;
case 4 : sm00010_00="肆拾";break;
case 5 : sm00010_00="伍拾";break;
case 6 : sm00010_00="陆拾";break;
case 7 : sm00010_00="柒拾";break;
case 8 : sm00010_00="捌拾";break;
case 9 : sm00010_00="玖拾";break;
};
switch(m00001_00)
{
case 0 : sm00001_00="";break;
case 1 : sm00001_00="壹";break;
case 2 : sm00001_00="贰";break;
case 3 : sm00001_00="叁";break;
case 4 : sm00001_00="肆";break;
case 5 : sm00001_00="伍";break;
case 6 : sm00001_00="陆";break;
case 7 : sm00001_00="柒";break;
case 8 : sm00001_00="捌";break;
case 9 : sm00001_00="玖";break;
};
switch(m00000_10)
{
case 0 : sm00000_10="";break;
case 1 : sm00000_10="壹角";break;
case 2 : sm00000_10="贰角";break;
case 3 : sm00000_10="叁角";break;
case 4 : sm00000_10="肆角";break;
case 5 : sm00000_10="伍角";break;
case 6 : sm00000_10="陆角";break;
case 7 : sm00000_10="柒角";break;
case 8 : sm00000_10="捌角";break;
case 9 : sm00000_10="玖角";break;
};
switch(m00000_01)
{
case 0 : sm00000_01="";break;
case 1 : sm00000_01="壹分";break;
case 2 : sm00000_01="贰分";break;
case 3 : sm00000_01="叁分";break;
case 4 : sm00000_01="肆分";break;
case 5 : sm00000_01="伍分";break;
case 6 : sm00000_01="陆分";break;
case 7 : sm00000_01="柒分";break;
case 8 : sm00000_01="捌分";break;
case 9 : sm00000_01="玖分";break;
};


m_BCALL=m_BCALL+sm10000_00;

if(!(m_BCALL.IsEmpty())&&(m01000_00==0)&&((m00100_00!=0)||(m00010_00!=0)||(m00001_00!=0)||(m00000_10!=0)||(m00000_01!=0)))
m_BCALL=m_BCALL+Ling;
else m_BCALL=m_BCALL+sm01000_00;

if((!m_BCALL.IsEmpty())&&(m00100_00==0)&&(m01000_00!=0)&&((m00010_00!=0)||(m00001_00!=0)||(m00000_10!=0)||(m00000_01!=0)))
m_BCALL=m_BCALL+Ling;
else m_BCALL=m_BCALL+sm00100_00;

if((!m_BCALL.IsEmpty())&&(m00010_00==0)&&(m00100_00!=0)&&((m00001_00!=0)||(m00000_10!=0)||(m00000_01!=0)))
m_BCALL=m_BCALL+Ling;
else m_BCALL=m_BCALL+sm00010_00;

if((!m_BCALL.IsEmpty())&&(m00001_00==0)&&(m00001_00!=0)&&((m00000_10!=0)||(m00000_01!=0)))
m_BCALL=m_BCALL+Ling;
else m_BCALL=m_BCALL+sm00001_00;


if(!m_BCALL.IsEmpty())m_BCALL=m_BCALL+Yuan;

if((!m_BCALL.IsEmpty())&&(m00000_10==0)&&(m00000_01!=0))
m_BCALL=m_BCALL+Ling;
else m_BCALL=m_BCALL+sm00000_10;


if(!m_BCALL.IsEmpty())m_BCALL=m_BCALL+sm00000_01+"整";
//m_BCALL 是大写的字符串,但是只能翻译到万位,如果想增加位数,读懂代码应该不难。
//希望对你能有帮助。
linhui 2001-12-28
  • 打赏
  • 举报
回复
我也想知道!
__c 2001-12-28
  • 打赏
  • 举报
回复
zyf_1977(zyf)说的差不多了
算法可以这样:
个.十。百。千。万。和11111分别对应
用循环让她们分别对应
是0的不打印就OK了
至于输入是另一种形式的就可以不转换了
呵呵
linning2570 2001-12-28
  • 打赏
  • 举报
回复
┬┴┬┌─ ●─┬─  │─┼─┐ ●├─┤○
┴┬┴├┬ ┌─┼─ │◎ │ │ ○└┬┘●
─┼─││ │ │  ││─┴─┴ ──┼──
●│○││ ┴─┼─  │○  ● / │ \
linning2570 2001-12-28
  • 打赏
  • 举报
回复
((`'-"``""-'`))
        )  -  - (
       /  (o _ o)         \  ( 0 )  /
       _'-.._'='_..-'_
      /`;#'#'#.-.#'#'#;`      \_))  '#'  ((_/
       #. ☆ ☆ ☆  #
       '#. 元旦快乐.#'
       / '#.   .#'        _\ \'#. .#'/ /_
      (((___) '#' (___)))
robothn 2001-12-28
  • 打赏
  • 举报
回复
定义一个位置变量可以避免你定义的那摸多"X千" "X分"
(unsigned long)1000000000000000.01 *100 变成一个长整形
switch (pos)
{
case 0: ch="分";break;
case 1: ch="角";break;
...
}
加载更多回复(17)

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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