PTA_输入符号及符号个数打印沙漏(C++)
思路:想将所有沙漏所需符号数遍历一遍,然后根据输入的数判断需要输出多少多少层的沙漏,然后分两部分输出沙漏。
作者:Vansnc
来源:CSDN
原文:https://blog.csdn.net/vansnc/article/details/81458526
版权声明:本文为博主原创文章,转载请附上博文链接!
1 #include--------------------------------------------------------------------------------------------------------------------------------------------------------------2 #include 3 using namespace std; 4 int main() 5 { 6 int z=0; 7 char fir[20]="0"; 8 int sec[20]={0},thi[20]={0},fo[21]={0}; 9 int len=0; 10 cin>>fir; 11 len=strlen(fir); 12 int len2=len; 13 for(int i=0;i '0'; 14 int i=len-1; 15 for(i;i>0;i--) 16 { 17 thi[i]=2*sec[i]+z; 18 z=thi[i]/10; 19 thi[i]%=10; 20 } 21 int t=thi[i]; 22 23 thi[i]=2*sec[i]+z; 24 if(t>=10) 25 { 26 len2++; 27 thi[i]=2*sec[i]+z; 28 fo[0]=thi[i]/10 ; 29 thi[i]%=10; 30 for(int j=0;j 1]=thi[j]; 31 } 32 else 33 { 34 thi[i]=2*sec[i]+z; 35 for(int j=0;j thi[j]; 36 } 37 38 z=0; 39 for(int k=0;k ) 40 { 41 for(int j=0;j ) 42 { 43 if(sec[j]==fo[k]){sec[j]=100;z=11;break;} 44 } 45 if(z!=11) {z=0;break;} 46 if(z==11) z=10; 47 48 } 49 50 if(z==10) 51 { 52 cout<<"Yes"<<endl; 53 for(int j=0;j fo[j]; 54 } 55 if(z!=10) 56 { 57 cout<<"No"<<endl; 58 for(int j=0;j fo[j]; 59 } 60 return 0; 61 }
作者:Vansnc
来源:CSDN
原文:https://blog.csdn.net/vansnc/article/details/81458526
版权声明:本文为博主原创文章,转载请附上博文链接!