青島理工邀請賽(難受的一次經歷)之顯示屏(按著倍數放大數字)
阿新 • • 發佈:2018-12-11
這是一次慘痛的經歷,三個人照著一個連知識點也沒有聽過的題做了三個小時,把這個水題給放過去了。哇呀呀,難受的一批啊。 題目描述:就是按著放大的倍數放大數字 程式碼如下:
#include<iostream> #include<cstdio> #include<cstring> using namespace std; char a[11]; int k; int main() { while(cin>>k>>a) { if(k==0||!strcmp(a,"0")) break; int len=strlen(a); for(int i=0;i<2*k+3;i++) { for(int j=0;j<len;j++) { if(i==0) { if(a[j]=='0'||a[j]=='2'||a[j]=='3'||a[j]=='5'||a[j]=='6'||a[j]=='7'||a[j]=='8'||a[j]=='9') { for(int m=0;m<k+2;m++) { if(m==0) cout<<" "; else if(m!=k+1) cout<<"-"; } cout<<" "; } else if(a[j]=='4') { for(int m=0;m<k+2;m++) cout<<" "; cout<<" "; } else cout<<" "; } else if(i>=1&&i<=k) { if(a[j]=='0'||a[j]=='8'||a[j]=='9'||a[j]=='4') { for(int m=0;m<k+2;m++) { if(m==0||m==k+1) cout<<"|"; else cout<<" "; } cout<<" "; } else if(a[j]=='2'||a[j]=='3'||a[j]=='7') { for(int m=0;m<k+2;m++) { if(m==k+1) cout<<"|"; else cout<<" "; } cout<<" "; } else if(a[j]=='5'||a[j]=='6') { for(int m=0;m<k+2;m++) { if(m==0) cout<<"|"; else cout<<" "; } cout<<" "; } else if(a[j]=='1') { cout<<"|"; cout<<" "; } } else if(i==k+1) { if(a[j]=='1') { cout<<" "; cout<<" "; } else if(a[j]=='0'||a[j]=='7') { for(int m=0;m<k+2;m++) { cout<<" "; } cout<<" "; } else { for(int m=0;m<k+2;m++) { if(m==0||m==k+1) cout<<" "; else cout<<"-"; } cout<<" "; } } else if(i>k+1&&i<2*k+2) { if(a[j]=='1') { cout<<"|"; cout<<" "; } else if(a[j]=='2') { for(int m=0;m<k+2;m++) { if(m==0) cout<<"|"; else cout<<" "; } cout<<" "; } else if(a[j]=='3'||a[j]=='4'||a[j]=='5'||a[j]=='7'||a[j]=='9') { for(int m=0;m<k+2;m++) { if(m==k+1) cout<<"|"; else cout<<" "; } cout<<" "; } else { for(int m=0;m<k+2;m++) { if(m==0||m==k+1) cout<<"|"; else cout<<" "; } cout<<" "; } } else if(i==2*k+2) { if(a[j]=='1') { cout<<" "; cout<<" "; } else if(a[j]=='7'||a[j]=='4') { for(int m=0;m<k+2;m++) cout<<" "; cout<<" "; } else { for(int m=0;m<k+2;m++) { if(m==0||m==k+1) cout<<" "; else cout<<"-"; } cout<<" "; } } } cout<<endl; } cout<<endl; } } ```就是從第一層開始一層一層的往下弄,找尋各個數的相同特點。仔細寫寫就好了。 233,加油