zoukankan      html  css  js  c++  java
  • vj p1024题解

    原题叙述

    此题很简单,搜索题。

    按照步骤老老实实的做就能过,不过这题要注意要用int64,高精也可以。虽然题目要求的是说maxlongint以内,但是由于倒过来就不只maxlongint了。

    另:记得补0和自己本身有可能是循环节。

    代码如下:

    var n,k,r:int64;
        g,i,j,l:longint;
        a:
    array[0..10000]of int64;
        over:boolean;
        t:string;
        num:
    array[0..9]of longint;
    procedure make(g:longint;n:int64;var a,b:int64);
              
    var s:string;i,j:longint;z:int64;
    begin
         fillchar(num,sizeof(num),
    0);
         str(n,s);
         
    for i:=1 to length(s) do
             
    begin
                  inc(num[ord(s[i])
    -ord('0')]);
             
    end;
         z:
    =1;
         a:
    =0;
         i:
    =0;
         
    for i:=0 to 9 do
             
    begin
                  
    if num[i]<>0 then
                     
    begin
                          
    for j:=1 to num[i] do
                              
    begin
                                   a:
    =a+i*z;
                                   z:
    =z*10;
                              
    end;
                     
    end;
             
    end;
         z:
    =1;
         b:
    =0;
         
    for i:=9 downto 0 do
             
    begin
                  
    if num[i]<>0 then
                     
    begin
                          
    for j:=1 to num[i] do
                              
    begin
                                   dec(num[i]);
                                   b:
    =b+i*z;
                                   z:
    =z*10;
                              
    end;
                     
    end;
             
    end;
    end;
    begin
         
    while not(eof) do
               
    begin
                    readln(n);
                    str(n,t);
                    g:
    =length(t);
                    make(g,n,k,r);
                    r:
    =k-r;
                    a[
    1]:=n;
                    l:
    =2;
                    a[
    2]:=r;
                    over:
    =false;
                    
    while not(over) do
                          
    begin
                               make(g,a[l],k,r);
                               inc(l);
                               a[l]:
    =k-r;
                               
    for i:=l-1 downto 1 do
                                   
    begin
                                        
    if a[l]=a[i] then
                                           
    begin
                                                
    for j:=to l-1 do write(a[j],' ');
                                                writeln;
                                                over:
    =true;
                                                break;
                                           
    end;
                                   
    end;
                          
    end;
               
    end;
    end.
  • 相关阅读:
    【NX二次开发】Block UI 组
    【NX二次开发】Block UI 双精度表
    【NX二次开发】Block UI 整数表
    自己写的简单的轮播图
    微信分享到朋友圈----摘录
    HTML5比较实用的代码
    苏格拉底的名言警句
    jQuery 幻灯片 ----摘录
    DeDe调用指定栏目ID下的文章
    JQuery 判断ie7|| ie8
  • 原文地址:https://www.cnblogs.com/waterfalleagle/p/1597721.html
Copyright © 2011-2022 走看看