现在的位置: 首页 > 综合 > 正文

POJ1102-模拟

2013年02月19日 ⁄ 综合 ⁄ 共 1815字 ⁄ 字号 评论关闭

题目:题目链接

 

题意:给出一个数字,按照要求的宽度大小输出LD式的数字表示

 

分析:模拟,把n是1的情况先一个数字一个数字搞出来。然后再根据n放大。蛋疼的模拟......

 

代码:

 

#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <map>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <functional>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <bitset>
#include <stack>
#include <ctime>
#include <list>
#define INF 0x7fffffff
#define max3(a,b,c) (max(a,b)>c?max(a,b):c)
#define min3(a,b,c) (min(a,b)<c?min(a,b):c)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;

int QuickMod(int  a,int b,int n)
{
    int r = 1;
    while(b)
    {
        if(b&1)
            r = (r*a)%n;
        a = (a*a)%n;
        b >>= 1;
    }
    return r;
}
char nums[10][5][3] =
{
    {{' ', '-', ' '}, {'|', ' ', '|'}, {' ', ' ', ' '}, {'|', ' ', '|'}, {' ', '-', ' '}},
    {{' ', ' ', ' '}, {' ', ' ', '|'}, {' ', ' ', ' '}, {' ', ' ', '|'}, {' ', ' ', ' '}},
    {{' ', '-', ' '}, {' ', ' ', '|'}, {' ', '-', ' '}, {'|', ' ', ' '}, {' ', '-', ' '}},
    {{' ', '-', ' '}, {' ', ' ', '|'}, {' ', '-', ' '}, {' ', ' ', '|'}, {' ', '-', ' '}},
    {{' ', ' ', ' '}, {'|', ' ', '|'}, {' ', '-', ' '}, {' ', ' ', '|'}, {' ', ' ', ' '}},
    {{' ', '-', ' '}, {'|', ' ', ' '}, {' ', '-', ' '}, {' ', ' ', '|'}, {' ', '-', ' '}},
    {{' ', '-', ' '}, {'|', ' ', ' '}, {' ', '-', ' '}, {'|', ' ', '|'}, {' ', '-', ' '}},
    {{' ', '-', ' '}, {' ', ' ', '|'}, {' ', ' ', ' '}, {' ', ' ', '|'}, {' ', ' ', ' '}},
    {{' ', '-', ' '}, {'|', ' ', '|'}, {' ', '-', ' '}, {'|', ' ', '|'}, {' ', '-', ' '}},
    {{' ', '-', ' '}, {'|', ' ', '|'}, {' ', '-', ' '}, {' ', ' ', '|'}, {' ', '-', ' '}}
};
int main()
{
    int i, x, jj, kk;
    int n, m, digits[20];
    while(scanf("%d%d", &n, &m) == 2)
    {
        if(!n && !m)
            break;
        i = 0;
        if(m == 0) //注意0
        {
            x = 1;
            digits[0] = 0;
        }
        else
        {
            //转为单个数字放在数组里
            while(m > 0)
            {
                digits[i] = m % 10;
                m = m / 10;
                i++;
            }
            x = i; 

        }

        for(int j = 0; j < 2*n+3; ++j)
        {
            jj = j;
            if(j > 0 && j <= n)
                jj = 1;
            if(j == n+1)
                jj = 2;
            if(j > n+1 && j < 2*n+3-1)
                jj = 3;
            if(j == 2*n+3-1)
                jj = 4;
            for(i = x-1; i >= 0; --i)
            {
                for(int k = 0; k < n+2; ++k)
                {
                    kk = 0;
                    if(k > 0 && k < n+1)
                        kk = 1;
                    if(k == n+1)
                        kk = 2;
                    printf("%c", nums[digits[i]][jj][kk]);
                }
                printf(" "); //数字之间要有空格
            }
            printf("\n");
        }
        printf("\n"); //输出一个数据后要有空行
    }
    return 0;
}

蛋疼.....

抱歉!评论已关闭.