标题:给你一个三位正整数,输出相应读法的汉语拼音,每个音之间用一个空格间隔。菜 ...
只看楼主
迷路的小炮车
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2017-4-24
结帖率:100%
已结贴  问题点数:20 回复次数:7 
给你一个三位正整数,输出相应读法的汉语拼音,每个音之间用一个空格间隔。菜鸟总是搞不出来...
#include <stdio.h>
int main(int argc,char *argv[]){
    int n,t,N,i=0;
    char y[][4]={"\n","yi","er","san","si","wu","liu","qi","ba","jiu"};
    scanf("%d",&N);
    for(i=0;i<N;i++)
        scanf("%d",&n);
    {for(i=0;i<N;i++)
    printf("%s bai",y[n/100]);
    {if((t=n/10%10) && n%10)
    printf(" %s shi %s ",y[t],y[n%10]);
     if(t==0 && n%10)
        printf(" ling %s ",y[n%10]);
    printf("\n");
    }
    }
}
搜索更多相关主题的帖子: 汉语拼音 include 正整数 
2017-04-25 01:22
迷路的小炮车
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2017-4-24
得分:0 
心痛
2017-04-25 08:53
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
得分:10 
程序代码:
#include <stdio.h>

int main(int argc,char *argv[])
{
    int n=123;
    char* y[]={"","","","","","","","","",""};
    printf("%s 佰 %s 拾 %s \n",y[n/100],y[(n/10)%10],y[n%10]);
    return 0;
} 

DO IT YOURSELF !
2017-04-25 09:08
迷路的小炮车
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2017-4-24
得分:0 
回复 3楼 wp231957
对不起对不起前辈,辛苦您了
我没有呈现清楚题目的要求

2017-04-25 12:26
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
得分:0 
这样呢
程序代码:
#include <stdio.h>

int main(int argc,char *argv[])
{
    int s[20];
    int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&s[i]);
    char* y[]={"","","","","","","","","",""};
    for(i=0;i<n;i++)
    {
        int bai=s[i]/100;
        int shi=(s[i]/10)%10;
        int ge=s[i]%10;
        printf("%s",y[bai]);
        if(shi!=0 && ge==0)
        {
            printf("佰%s拾",y[shi]);
        }
        else if(shi==0 && ge==0)
        {
            printf("");
        }
        else if(shi==0 && ge!=0)
        {
            printf("佰%s%s",y[shi],y[ge]);
        }
        else if(shi!=0 && ge!=0)
        {
            printf("佰%s拾%s",y[shi],y[ge]);
        }
        printf("\n");
    }
    return 0;
}


[此贴子已经被作者于2017-4-25 13:46编辑过]


DO IT YOURSELF !
2017-04-25 13:43
renkejun1942
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:不是这样
等 级:贵宾
威 望:33
帖 子:1645
专家分:5297
注 册:2016-12-1
得分:10 
类似的程序我写过一个,但并不完善(我忘记什么地方不完善了),但用来参考应该足够了。
程序代码:
#include <stdio.h>
#include <string.h>

void
written_amount( unsigned int amount, char *buffer );

int
main( void )
{
    char buffer[1000];
    unsigned int a;

    while( 1 == scanf("%u",&a) )
    {
        written_amount( a, buffer );

        printf("%d\n",a);
        printf("%s\n",buffer);
    }

    return 0;
}

static char *nums[] = { "ling ", "yi ", "er ", "san ", "si ", "wu ", "liu ", "qi ", "ba ", "jiu " };
static char *magnitudes[] ={ "","shi ","bai ","qian ","wan ","shiwan ","baiwan ","qianwan ","yi " };

void
written_amount( unsigned int amount, char *buffer )
{
    unsigned int value;
    unsigned int count;
    unsigned int num, prev;
    unsigned int magnitude;

    value = amount / 10;
    magnitude = 1;
    buffer[0] = '\0';

    if( 0 == amount )
        strcat( buffer, nums[ amount ] );

    for( count = 0; 0 < value; count++, value /= 10, magnitude *= 10 )
        ;


    for( value = amount, prev = 1; 0 < value; count--, magnitude /= 10 )
    {
        num = value / magnitude;
        value %= magnitude;

        if( 0 != num  || 0 != prev )
            strcat( buffer, nums[ num ] );
        if( 0 != num )
            strcat( buffer, magnitudes[ count ] );
        prev = num;
        
    }
}


09:30 05/21 种下琵琶种子,能种活么?等待中……
21:50 05/27 没有发芽。
20:51 05/28 没有发芽。
23:03 05/29 没有发芽。
23:30 06/09 我有预感,要发芽了。
2017-04-25 13:57
迷路的小炮车
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2017-4-24
得分:0 
回复 5楼 wp231957
感谢感谢!
2017-04-26 13:18
迷路的小炮车
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2017-4-24
得分:0 
回复 6楼 renkejun1942
不胜感激~学习一波
2017-04-26 13:19



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-476406-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.138258 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved