poj1102 LC-Display

來源:互聯網
上載者:User

呵呵。。。

這道題是一位隊友向我推薦的,當時因為看英文題看得頭都大了,本不想做A題了。但這道題只需看下輸入輸出就能明白題目大意, 太爽了! 咱就不喜歡他媽的一個題目頁來長。

其實這道題就是考簡單的輸入輸出問題。

代碼如下:

#include<iostream>using namespace std;/* ----  //b[0]|    ||    ||    | //c[0][2]|    | ----  //b[1]|    ||    | // c[1][2]|    ||    | ----  //b[2] 如,是一個數位基本架構,可以為分2類,輸出‘-’部分(行)、‘|’部分(多行)。 下面的b數組是用來描述‘-’部分的有無, c數組是用來描述‘|’部分的有無。*/int b[3][10] = {{1, 0, 1, 1, 0, 1, 1, 1, 1, 1}, {0, 0, 1, 1, 1, 1, 1, 0, 1, 1}, {1, 0, 1, 1, 0, 1, 1, 0, 1, 1}};int c[2][10][2] = {{{1, 1}, {0, 1}, {0, 1}, {0, 1}, {1, 1}, {1, 0}, {1, 0}, {0, 1}, {1, 1}, {1, 1}}, {{1, 1}, {0, 1}, {1, 0}, {0, 1}, {0, 1}, {0, 1}, {1, 1}, {0, 1}, {1, 1}, {0, 1}}};int s, n;int digit[20];void f(int a[], int n){int i,j,k;for(i=1; i<=n; i++){cout<<' ';for(j=0; j<s; j++)if(a[digit[i]] == 1)cout<<'-';elsecout<<' ';cout<<' ';if(i != n)cout<<' ';}cout<<endl;}void g(int a[][2], int n){int i,j,k;for(i=1; i<=n; i++){if(a[digit[i]][0] == 1)cout<<'|';else cout<<' ';for(j=0; j<s; j++)cout<<' ';if(a[digit[i]][1] == 1)cout<<'|';else cout<<' ';if(i != n)cout<<' ';}cout<<endl;}int main(){int dec[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000};while(cin>>s>>n && s*s+n*n != 0){int i,j,k;int count = 0;for(i=1; i<=8 && count == 0; i++)if(n < dec[i])count = i;for(i=1; i<=count; i++){digit[i] = n/dec[count-i];n = n%dec[count-i];}f(b[0], count);for(i=0; i<s; i++)g(c[0], count);f(b[1], count);for(i=0; i<s; i++)g(c[1], count);f(b[2], count);cout<<endl;}return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.