zoukankan      html  css  js  c++  java
  • PTA_输入符号及符号个数打印沙漏(C++)

    思路:想将所有沙漏所需符号数遍历一遍,然后根据输入的数判断需要输出多少多少层的沙漏,然后分两部分输出沙漏。
     
     1 #include<iostream>
     2 #include<cstring>
     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<len;i++) sec[i]=fir[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<len;j++) fo[j+1]=thi[j];
    31     }
    32     else 
    33     {
    34         thi[i]=2*sec[i]+z;
    35         for(int j=0;j<len2;j++) fo[j]=thi[j];
    36     }
    37         
    38     z=0;
    39     for(int k=0;k<len2;k++)
    40     {
    41         for(int j=0;j<len;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<len2;j++) cout<<fo[j];
    54     }
    55     if(z!=10)
    56     {
    57         cout<<"No"<<endl;
    58         for(int j=0;j<len2;j++) cout<<fo[j];
    59     }
    60     return 0;
    61 } 
    --------------------------------------------------------------------------------------------------------------------------------------------------------------
    作者:Vansnc
    来源:CSDN
    原文:https://blog.csdn.net/vansnc/article/details/81458526
    版权声明:本文为博主原创文章,转载请附上博文链接!
  • 相关阅读:
    奶酪工厂
    P1080 国王游戏(非高精版)
    【洛谷P2150】[NOI2015] 寿司晚宴
    【洛谷P3349】[ZJOI2016]小星星
    【洛谷P5785】[SDOI2012]任务安排
    【模板】严格次短路
    【洛谷P3647】[APIO2014]连珠线
    2021.10.27NOIP模拟总结
    【树形DP】CF1016F Road Projects
    2021CSP-S 总结
  • 原文地址:https://www.cnblogs.com/Yethon/p/10457900.html
Copyright © 2011-2022 走看看