首页 > 其他 > 详细

编程总结2

时间:2019-02-21 13:51:09      阅读:188      评论:0      收藏:0      [点我收藏+]

1.实验代码

#include<bits/stdc++.h>
using namespace std;
int main (int argc,const char * argv[])
{
    int n, initial_n;
    scanf("%d", &n);
    initial_n = n; 
 
    char num[10] = {a, b, c, d, e, f, g, h, i, j};
    char unit[10] = {0, 0, S, B, Q, W, S, B, Q, Y};
    char result[17]={0}; 
    
    int i, last_i = n % 10; 
    int j = 0;
    int count_n = 0;
    while (n > 0) {
        i = n % 10;
        n /= 10;
        count_n ++;
        if (i == 0 && (count_n % 4) > 1) { 
            if (last_i != 0) {  
                result[j++]  = num[i];    
            } 
        }
        if (count_n == 5 && i == 0 && initial_n < 100000000) {result[j++] =  unit[count_n]; }
        if (count_n > 1 && i != 0) {result[j++] = unit[count_n];} 
        if (i != 0) {result[j++] = num[i];}
        last_i = i; 
    }
    
    if (initial_n == 0) {   result[j++]  = num[i];} 
    
    for (j=j-1; j>=0; j--) {printf("%c", result[j]);}
    cout<<endl;
    
    return 0;
}

 

2.设计思路

先用循环把位数和每一位提取出来,然后对应之前设好的字符数组的中的字母一一打印。

 

3.实验过程中遇到的问题

一个特殊情况不超过亿中间连续多0的情况未考虑。

 

4.运行结果截图

技术分享图片

 

编程总结2

原文:https://www.cnblogs.com/xiangqi/p/10411936.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!