請不要直接抄寫程式碼! 也請不要直接跳到程式碼部分,除非你已經寫好了,想要參考別人的寫法!
#include <iostream>
using namespace std;
int main()
{
string number;
cin>>number;
// firstLine
for(int i=0;i<3;i++){
switch(number[i]-48){
case 1:
cout<<" *";
break;
case 4:
cout<<"* *";
break;
default:
cout<<"*****";
break;
}
if(i!=2)
cout<<" ";
}
cout<<endl;
// secondLine
for(int i=0;i<3;i++){
switch(number[i]-48){
case 1:
case 2:
case 3:
case 7:
cout<<" *";
break;
case 5:
case 6:
cout<<"* ";
break;
default:
cout<<"* *";
break;
}
if(i!=2)
cout<<" ";
}
cout<<endl;
// thirdLine
for(int i=0;i<3;i++){
switch(number[i]-48){
case 0:
cout<<"* *";
break;
case 1:
case 7:
cout<<" *";
break;
default:
cout<<"*****";
break;
}
if(i!=2)
cout<<" ";
}
cout<<endl;
// fourthLine
for(int i=0;i<3;i++){
switch(number[i]-48){
case 2:
cout<<"* ";
break;
case 0:
case 6:
case 8:
cout<<"* *";
break;
default:
cout<<" *";
break;
}
if(i!=2)
cout<<" ";
}
cout<<endl;
// fifthLine
for(int i=0;i<3;i++){
switch(number[i]-48){
case 1:
case 4:
case 7:
cout<<" *";
break;
default:
cout<<"*****";
break;
}
if(i!=2)
cout<<" ";
}
cout<<endl;
}
如果有任何問題,歡迎私訊跟我討論喔!