| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5835 人关注过本帖
标题:币值转换
只看楼主 加入收藏
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
回复 19 楼 wp231957
好久不见。诸事纷繁,万哥近来可好。

顺道回复20楼,核心就那一个循环三句代码,解释开来话就长了,倒不如细看看那几句代码。数组b是一个映射表结合题意看也不难理解。

至于算法,就是找汉语读数字的规律,英语的习惯是千分组,汉语则习惯以万分组,需要注意的是零的读法处理,尽在那三个if表达式里。

重剑无锋,大巧不工
2014-08-13 21:58
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
回复 21 楼 beyondyf
老样子  没啥变化  呵呵

DO IT YOURSELF !
2014-08-14 08:16
三个人
Rank: 2
等 级:论坛游民
帖 子:54
专家分:40
注 册:2014-7-6
收藏
得分:0 
回复 18 楼 beyondyf
通过,,但是我真心看不懂
不过谢谢你!
2014-08-19 18:05
MD10
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2015-11-25
收藏
得分:0 
回复 楼主 三个人
楼主看看我的怎么样
刚做了下,话说情况真的好多TvT
#include<stdio.h>
int main(void)
{
    int in, i=0,j=0,total,flag=0;
    char a[10] = { '\0' }, b[8] = { 'Y', 'Q', 'B', 'S', 'W', 'Q', 'B', 'S' };
    while (a[i] = getchar(),a[i] !='\n')
    {
        i++;
    }
    a[i] = '\0';
    if (a[0] == '0')
        printf("a");
    total = i;
    i = 8;
    while (a[i] == '\0'||a[i] == '0')
    {
        j++;
        i--;
    }
    if (j == 8)
        printf("%cY", a[0]);
    else
    {
        for (i = 0; i <= 8 - j; i++)
        {
            while (a[i] == '0')
            {
                flag = 1;
                if ((9 - total + i) == 4)
                    printf("%c", b[4]);
                i++;
            }
            if (flag)
            {
                i--;
                printf("%c", a[i]-'0'+'a');
                flag = 0;
                i++;
            }
            if (i != total)
                printf("%c%c", a[i]-'0'+'a', b[9 - total + i]);
            else
                printf("%c", a[i]-'0'+'a');
        }
        if (j > 9 - total)
        {
            if (total > 6)
                printf("%c", b[4]);
        }
    }
}
2015-11-25 23:45
lpirate
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-1-12
收藏
得分:0 
回复 12楼 三个人
#include <stdio.h>
void Switch(int idx, int a[]);

int main(int argc, char const *argv[])
{
    int n = 0;
    int cnt = 0;
    int a[10];
    for (int i = 0; i < 10; i++) {
        a[i] = 0;
    }
   
   
        scanf("%d", &n);
        
        int temp = n;
        while (temp) {
            a[cnt] = temp % 10;
            temp = temp / 10;
            cnt++;
        }
        
        
        
        for (int i = cnt-1; i >= 0; i--) {
            Switch(i, a);
        }
    if (n == 0) {
        printf("a");
    }
        
        printf("\n");

   
    return 0;
}

void Switch(int idx, int a[])
{
    int flag = 0;
   
    int IDX = 0;
    int flag_not_0 = 0;
    switch (a[idx]) {
        case 0:
            if (idx <= 3) {
                for (int i = idx; i <= 8; i++) {
                    if (a[i]) {
                        IDX = i;
                        flag = 1;
                        break;
                    }
                }
                for (int i = idx+1; i <= IDX; i++) {
                    if (a[i] == 0) {
                        flag = 0;
                        break;
                    }
                }
               
                for (int i = idx; i >= 0; i--) {
                    if (a[i]) {
                        flag_not_0 = 1;
                        break;
                    }
                }
               
                if (flag && flag_not_0) {
                    printf("a");
                }

            }else{
                for (int i = idx; i <= 8; i++) {
                    if (a[i]) {
                        IDX = i;
                        flag = 1;
                        break;
                    }
                }
                for (int i = idx+1; i <= IDX; i++) {
                    if (a[i] == 0) {
                        flag = 0;
                        break;
                    }
                }
               
                for (int i = idx; i >= 4; i--) {
                    if (a[i]) {
                        flag_not_0 = 1;
                        break;
                    }
                }
               
                if (flag && flag_not_0) {
                    printf("a");
                }

               
            }
            
            break;
        case 1:
            if (idx == 1) {
                if (a[2] || a[3] ||a[4] ||a[5] || a[6]  ||a[7] || a[8] )
                {
                    printf("b");
                }else{
                    
                }
            }else if(idx == 5){
                if ( a[6] ||a[7] || a[8])
                {
                    printf("b");
                }else{
                    
                }
               
            }else{
                printf("b");
            }
            break;
        case 2:
            printf("c");
            break;
        case 3:
            printf("d");
            break;
        case 4:
            printf("e");
            break;
        case 5:
            printf("f");
            break;
        case 6:
            printf("g");
            break;
        case 7:
            printf("h");
            break;
        case 8:
            printf("i");
            break;
        case 9:
            printf("j");
            break;
    }
   
   
   
   
    switch (idx) {
        case 1:
            if (a[idx]) {
                printf("S");
            }
            break;
        case 2:
            if (a[idx]) {
                printf("B");
            }
            break;
        case 3:
            if (a[idx]) {
                printf("Q");
            }
            break;
        case 4:
            if (a[4] || a[5] || a[6] || a[7]) {
                printf("W");
                if (a[4] == 0 || (a[4]==0 && a[5]==0 )  ||( a[4]==0 &&a[5] ==0 && a[6] == 0)) {
                    printf("a");
                }
               
            }
            break;
        case 5:
            if (a[idx]) {
                printf("S");
            }
            break;
        case 6:
            if (a[idx]) {
                printf("B");
            }
            break;
        case 7:
            if (a[idx]) {
                printf("Q");
            }
            break;
        case 8:
            printf("Y");
            break;
        default:
            break;
    }

}

2016-01-12 14:30
lpirate
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-1-12
收藏
得分:0 
被最后的零弄哭了
2016-01-12 14:30
快速回复:币值转换
数据加载中...
 
   



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

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