題目1. 矩陣數字顯示
問題描述
現有一可顯示四位數字的 LED 燈一組,可根據輸入的四位數字顯示數字。比如說,
由鍵盤輸入 1234 ,則可在螢幕上顯示
若輸入 0789 ,則顯示
輸入格式
輸入格式為 四個整數。
輸出格式
輸出值為輸入值的矩陣數字。
Example
現有一可顯示四位數字的 LED 燈一組,可根據輸入的四位數字顯示數字。比如說,
由鍵盤輸入 1234 ,則可在螢幕上顯示
若輸入 0789 ,則顯示
輸入格式
輸入格式為 四個整數。
輸出格式
輸出值為輸入值的矩陣數字。
Example
Sample Input:
| Sample Output: |
0789 |
- #include <iostream>
- #include <stdio.h>
- #include <string.h>
- using namespace std;
- int main() {
- // 題目1. 矩陣數字顯示
- string num[10][5];
- num[0][0] = "*****";
- num[0][1] = "* *";
- num[0][2] = "* *";
- num[0][3] = "* *";
- num[0][4] = "*****";
- num[1][0] = " *";
- num[1][1] = " *";
- num[1][2] = " *";
- num[1][3] = " *";
- num[1][4] = " *";
- num[2][0] = "*****";
- num[2][1] = " *";
- num[2][2] = "*****";
- num[2][3] = "* ";
- num[2][4] = "*****";
- num[3][0] = "*****";
- num[3][1] = " *";
- num[3][2] = "*****";
- num[3][3] = " *";
- num[3][4] = "*****";
- num[4][0] = "* *";
- num[4][1] = "* *";
- num[4][2] = "*****";
- num[4][3] = " *";
- num[4][4] = " *";
- num[5][0] = "*****";
- num[5][1] = "* ";
- num[5][2] = "*****";
- num[5][3] = " *";
- num[5][4] = "*****";
- num[6][0] = "*****";
- num[6][1] = "* ";
- num[6][2] = "*****";
- num[6][3] = "* *";
- num[6][4] = "*****";
- num[7][0] = "*****";
- num[7][1] = " *";
- num[7][2] = " *";
- num[7][3] = " *";
- num[7][4] = " *";
- num[8][0] = "*****";
- num[8][1] = "* *";
- num[8][2] = "*****";
- num[8][3] = "* *";
- num[8][4] = "*****";
- num[9][0] = "*****";
- num[9][1] = "* *";
- num[9][2] = "*****";
- num[9][3] = " *";
- num[9][4] = " *";
- string N;
- while(cin >> N)
- {
- char c[4];
- strcpy(c, N.c_str());
- for(int i = 0;i < 5;i++)
- {
- for(int j = 0;j < 4;j++)
- {
- if(j != 0)
- {
- cout << " " << num[c[j]-'0'][i];
- }
- else
- {
- cout << num[c[j]-'0'][i];
- }
- }
- cout << endl;
- }
- }
- return 0;
- }
沒有留言:
張貼留言