zoukankan      html  css  js  c++  java
  • [vijos1304]回文数<模拟>

    题目链接:https://vijos.org/p/1304

    好久没写博客了,最近一直打不出题,感觉自己是废了,今天做了一道模拟水题,但还是半天没过,后来才发现是忘记考虐10以上的进制是带有字母的,然后就处理字母去了。。接着就发现了一系列shabby一样的操作。。。

    这道题只有几个注意点:

    1.要考虑到10以上进制在输入是带有字母的

    2.这道题并不用把最后的答案输出来,所以直接用int类型存就行了

    3.11进制中A代表的是10而不是11,意思是在16进制中最大的是F而不是E

    4.这道题可以在数组中用数字代表字母,然后大于等于n就进位

    好吧然后这题本来就没难度,我只是简单打个博客水一水,表示我还活着。。。。

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 #include<iostream>
     5 #include<cstdlib>
     6 #include<cmath>
     7 #define maxn 30
     8 using namespace std;
     9 int n,len, s1[50],s2[50];
    10 char m;
    11 bool check(){
    12     for(int i=1;i<=len;i++)
    13      if(s1[i]!=s1[len-i+1])return false;
    14     return true;
    15 }
    16 void change(){
    17     for(int i=1;i<=len;i++){
    18         s2[len-i+1]=s1[i];
    19     }    
    20 }
    21 void show(){
    22     cout<<endl;
    23     for(int i=1;i<=len;i++)
    24      cout<<s1[i];cout<<endl;
    25     for(int i=1;i<=len;i++)
    26      cout<<s2[i];cout<<endl;    
    27 }
    28 int main(){
    29     scanf("%d",&n);
    30     while(scanf("%c",&m)!=EOF){
    31         if((m>='0'&&m<='9')||(m>='A'&&m<='F'))len++;
    32         else{if(len>=1)break;}
    33         if((m>='0'&&m<='9')){s1[len]=m-'0';}
    34         if((m>='A'&&m<='F')){s1[len]=m-'A'+10;}
    35     }    
    36     if(check()){
    37         puts("0");exit(0);
    38     }
    39     change();
    40     int step=1,jin=0;
    41     while(step<=30){
    42         for(int i=len;i>=1;i--){
    43             int new_=s1[i]+s2[i]+jin;
    44             jin=0;
    45             if(new_<n)s1[i]=new_;
    46             if(new_>=n){
    47                 jin=1;
    48                 s1[i]=new_-n;
    49             }
    50             if(jin==1&&i==1){
    51                 for(int i=len+1;i>=2;i--)
    52                  s1[i]=s1[i-1];
    53                 s1[1]=1;
    54                 len++;jin=0;
    55             }
    56         }
    57         change();
    58         if(check()){
    59             printf("STEP=%d",step);exit(0);
    60         }
    61         step++;
    62     }
    63     printf("Impossible!");
    64 }
    View Code
  • 相关阅读:
    jQuery火箭图标返回顶部代码
    jQuery火箭图标返回顶部代码
    All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters
    记一次odoo创建新的模块时,但是在odoo web界面找不到应用的案例
    python实现格式化输出9*9乘法表
    format和urlencode的使用对比
    python字典小知识
    01
    深浅拷贝再回顾
    DRF的路由生成类的使用
  • 原文地址:https://www.cnblogs.com/Danzel-Aria233/p/7638594.html
Copyright © 2011-2022 走看看