发一个很蛋疼的程序,将一个数字转化为液晶显示屏显示的样子:第一个输入是尺寸,第二输入是要转化的数字,当两个参数都为0的时候结束输入:
#include<iostream>
using namespace std;struct Print{int size;int numPrint;
};void printNum(Print print);int main(){Print *prints = new Print[10];int index = 0;int size;int numPrint;cin>>size;cin>>numPrint;while(size != 0 && numPrint != 0){Print *print = new Print();print->size = size;print->numPrint = numPrint;prints[index] = *print;index++;cin>>size;cin>>numPrint;}for(int i = 0; i < index; i++){printNum(prints[i]);cout<<endl<<endl;}system("pause");
}void printNum(Print print){int size = print.size;int numPrint = print.numPrint;int *nums = new int[8];int index = 0;while(numPrint != 0){int temp = numPrint - (numPrint / 10) * 10;nums[index] = temp;numPrint = numPrint / 10;index++;}for(int row = 0; row < 2*size + 3; row++){for(int i = index - 1; i >= 0; i--){if(row == 0){switch(nums[i]){case 1:case 4:for(int length = 0; length < size + 2; length++){cout<<" ";}break;default:cout<<" ";for(int length = 1; length < size + 1; length++){cout<<"-";}cout<<" ";break;}}if(row > 0 && row <size + 1){switch(nums[i]){case 1:case 2:case 3:case 7:for(int length = 0; length < size + 1; length++){cout<<" ";}cout<<"|";break;case 5:case 6:cout<<"|";for(int length = 0; length < size + 1; length++){cout<<" ";}break;case 4:case 8:case 9:case 0:cout<<"|";for(int length = 1; length < size + 1; length++){cout<<" ";}cout<<"|";break;}}if(row == size + 1){switch(nums[i]){case 2:case 3:case 4:case 5:case 6:case 8:case 9:cout<<" ";for(int length = 1; length < size + 1; length++){cout<<"-";}cout<<" ";break;default:for(int length = 0; length < size + 2; length++){cout<<" ";}break;}}if(row > size + 1 && row < 2*size+ 2){switch(nums[i]){case 1:case 3:case 5:case 4:case 7:case 9:for(int length = 1; length < size + 2; length++){cout<<" ";}cout<<"|";break;case 2:cout<<"|";for(int length = 1; length < size + 2; length++){cout<<" ";}break;default:cout<<"|";for(int length = 1; length < size + 1; length++){cout<<" ";}cout<<"|";break;}}if(row == 2*size+2){switch(nums[i]){case 1:case 4:case 7:for(int length = 0; length < size + 2; length++){cout<<" ";}break;default:cout<<" ";for(int length = 1; length < size + 1; length++){cout<<"-";}cout<<" ";break;}}}cout<<endl;}
}