• UVA 12050.Palindrome Numbers


     

    12050 - Palindrome Numbers

    Time limit: 3.000 seconds 

    A palindrome is a word, number, or phrase that reads the same forwards as backwards. For example, the name “anna” is a palindrome. Numbers can also be palindromes (e.g. 151 or 753357). Additionally numbers can of course be ordered in size. The first few palindrome numbers are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, ... The number 10 is not a palindrome (even though you could write it as 010) but a zero as leading digit is not allowed.
    Input

    The input consists of a series of lines with each line containing one integer value i (1 ≤ i ≤ 2∗109). This integer value i indicates the index of the palindrome number that is to be written to the output, where index 1 stands for the first palindrome number (1), index 2 stands for the second palindrome number (2) and so on. The input is terminated by a line containing ‘0’.
    Output
    For each line of input (except the last one) exactly one line of output containing a single (decimal) integer value is to be produced. For each input value i the i-th palindrome number is to be written to the output.
    Sample Input
    1

    12

    24

    0
    Sample Output
    1

    33

    151

    题意就是把第i个回文数输出来。

    长度为k的回文数有9*10(k-1)个,依次计算,得出n为长度多少的回文数,然后得出长度多少的第几个回文数,n计算完要-1.

    1-9 9

    10-99 9

    100-999 90

    1000-9999 90

    然后900 900 9000 9000。。。

    这个题好像又不会了。。。

    傻子(╯‵□′)╯︵┻━┻,用C语言交了10几次,格式错误,都不知道看一下用什么交的吗?(▼ヘ▼#)

    代码:

    #include<stdio.h>
    const int N=2*1e5;
    int n[N],i;
    int h,m[N];
    void gg(){
        n[0]=0,n[1]=n[2]=9;
        for(i=3;i<20;i+=2)
            n[i]=n[i+1]=n[i-1]*10;
    }
    int main(){
        gg();
        while(~scanf("%d",&h)&&h){
            int len=1;
            while(h>n[len]){
                h-=n[len];
                len++;
            }
            h--;
            int cnt=len/2+1;
            while(h!=0){
                m[cnt++]=h%10;
                h/=10;
            }
            for(i=cnt;i<=len;i++)
                m[i]=0;
                m[len]++;
            for(i=1;i<=len/2;i++){
                m[i]=m[len-i+1];
            }
            for(i=1;i<=len;i++)
                printf("%d",m[i]);
            printf("
    ");
        }
        return 0;
    }
  • 相关阅读:
    Persister使用说明
    获取一个目录下的所有文件名称
    bootstrap学习
    bootstrap.文章列表带头像及操作
    初识Lucene.net
    Lucene.net 高亮显示搜索词
    WP7.OnNavigatedTo和OnNavigatedFrom
    SL4.图片下载进度条
    SL4.基本数据验证
    SL4.数据绑定OneWay、OneTime、TwoWay
  • 原文地址:https://www.cnblogs.com/ZERO-/p/7112991.html
Copyright © 2020-2023  润新知