zoukankan      html  css  js  c++  java
  • Runaround Numbers chapter 2.2

      题目看懂了到是不难,直接枚举,不过调错真是调了好久,提交了12次才过啊啊啊啊啊

      1 /*
      2 
      3 ID: hubiao cave
      4 
      5 PROG: runround
      6 
      7 LANG: C++
      8 
      9 */
     10 
     11 
     12 
     13 
     14 #include<iostream>
     15 
     16 #include<fstream>
     17 #include<algorithm>
     18 #include<string>
     19 #include<cstring>
     20 
     21 using namespace std;
     22 
     23 
     24 
     25 
     26 int main()
     27 
     28 {
     29 
     30 
     31 
     32 
     33     ifstream fin("runround.in");
     34     ofstream fout("runround.out");
     35 
     36     int used[11]={0};
     37     int start;
     38     char buf[20]={0};
     39     fin>>start;
     40     int i=start;
     41 
     42 
     43     while(1)
     44     {
     45         memset(buf,0,20);
     46         memset(used,0,sizeof(int)*11);
     47 
     48         ++i;
     49         //_itoa(i,buf,10);
     50         sprintf(buf,"%d",i);
     51         string str=buf;
     52         if(str.find('0')!=-1)
     53             continue;
     54         int m=i;
     55 
     56 
     57         int flag=0;
     58         while(m/10>=1)
     59         {
     60             if(used[m%10])
     61             {
     62                 flag=1;
     63                 break;
     64             }
     65             else
     66             {
     67 
     68                 used[m%10]=1;
     69                 m/=10;
     70             }
     71         }
     72         if(flag)
     73             continue;
     74         if(used[m])
     75             continue;
     76         else
     77         {
     78             memset(used,0,sizeof(int)*11);
     79 
     80             int count=0;
     81             int sta=0;
     82             int starnum=str[0]-'0';
     83             int flag=0;
     84             while(count<str.size()-1)
     85             {
     86 
     87                 sta=sta+(str[sta]-'0')%str.size();
     88                 if(sta>=str.size())
     89                     sta%=str.size();
     90                 if(used[str[sta]-'0']||sta==0)
     91                 {
     92                     flag=1;
     93                     break;
     94                 }
     95                 else
     96                 {
     97                     used[str[sta]-'0']=1;
     98                 }
     99                 count++;
    100             }
    101 
    102             if(flag)
    103                 continue;
    104             sta=sta+(str[sta]-'0')%str.size();
    105             if(sta>=str.size())
    106                 sta%=str.size();
    107             if(sta==0)
    108             {
    109                 fout<<i<<endl;
    110                 break;
    111             }
    112         }
    113 
    114     }
    115 
    116     return 0;
    117 
    118 
    119 }
  • 相关阅读:
    jquery 序列化form表单
    nginx for windows 安装
    nodejs idea 创建项目 (一)
    spring 配置 shiro rememberMe
    idea 2018 解决 双击shift 弹出 search everywhere 搜索框的方法
    redis 在windows 集群
    spring IOC控制反转和DI依赖注入
    redis 的安装
    shiro 通过jdbc连接数据库
    handlebars的用法
  • 原文地址:https://www.cnblogs.com/cavehubiao/p/3292026.html
Copyright © 2011-2022 走看看