码迷,mamicode.com
首页 > 其他好文 > 详细

1002. 写出这个数 (20)

时间:2015-08-27 11:02:37      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

//
//  main.c
//  TrainingForC
//
//  Created by Deak on 15/8/21.
//  Copyright (c) 2015年 Shen.Jun. All rights reserved.
//

#include "stdio.h"
#include "math.h"
    int cnt = 1;
int bit (int n) {
    if (n/10 == 0) {
        return cnt;
    } else {
        cnt++;
        return bit(n/10);
    }
}
void print (int n) {
    switch (n) {
        case 0:
            printf("ling");
            break;
        case 1:
            printf("yi");break;
        case 2:
            printf("er");break;
        case 3:
            printf("san");break;
        case 4:
            printf("si");break;
        case 5:
            printf("wu");break;
        case 6:
            printf("liu");break;
        case 7:
            printf("qi");break;
        case 8:
            printf("ba");break;
        case 9:
            printf("jiu");break;
    }
}
int mypow(int n) {
    int ans = 1;
    for (int i = 0; i < n; i++) {
        ans *= 10;
    }
    return ans;
}
int main(void) {
    long long int n = 0,tar = 0;
    scanf("%lld",&n);
    printf("%lld",n);
    int w = bit(n),sum = 0;
    for (int i = 0; i < w; i++) {
        sum = sum+n/mypow(i)%10;
        }
    cnt = 1;
    w = bit(sum);
    for (int i = w; i > 1; i--) {
        tar = sum/mypow(i-1)%10;
        print(tar);
        printf(" ");
    }
    print(sum%10);
}


//

#include"stdio.h"
int cnt = 1;
int bit (int n) {
    if (n/10 == 0) {
        return cnt;
    } else {
        cnt++;
        return bit(n/10);
    }
}
int mypow(int n) {
    int ans = 1;
    for (int i = 0; i < n; i++) {
        ans *= 10;
    }
    return ans;
}

void print (int n) {
    switch (n) {
        case 0:
            printf("ling");
            break;
        case 1:
            printf("yi");break;
        case 2:
            printf("er");break;
        case 3:
            printf("san");break;
        case 4:
            printf("si");break;
        case 5:
            printf("wu");break;
        case 6:
            printf("liu");break;
        case 7:
            printf("qi");break;
        case 8:
            printf("ba");break;
        case 9:
            printf("jiu");break;
    }
}
int main(void) {
    char n[101] = {0};
    scanf("%s",&n);
    int sum = 0;
    for (int i = 0; i < 100; i++) {
        if (n[i] != \0) {
            sum += n[i] - 0;
        }
    }
    int w = 0, tar = 0;
    w = bit(sum);
    for (int i = w; i > 1; i--) {
        tar = sum/mypow(i-1)%10;
        print(tar);
        printf(" ");
    }
    print(sum%10);
}

 

1002. 写出这个数 (20)

标签:

原文地址:http://www.cnblogs.com/sjdeak/p/4762511.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!