zoukankan      html  css  js  c++  java
  • PTA_Have fun with numbers(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 } 
  • 相关阅读:
    Zookeeper服务器启动
    BeanFactoryPostProcessor
    ZK简介
    自定义标签解析
    高性能MySQL
    Redis原理
    ApplicationContext
    ThreadPoolExecutor
    NW.js构建PC收银端安装程序的指南
    NW.js安装原生node模块node-printer控制打印机
  • 原文地址:https://www.cnblogs.com/Yethon/p/10460168.html
Copyright © 2011-2022 走看看