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 ?rst 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 ?rst 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("\n");
    }
    return 0;
}

一开始把gg函数(。。。)放在main函数里面了,不可以,不知道为啥。。。

不会。。。

时间: 2024-10-10 14:12:45

UVA - 12050-Palindrome Numbers的相关文章

Uva - 12050 Palindrome Numbers【数论】

题目链接:uva 12050 - Palindrome Numbers 题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然后就得到是长度为多少的第几个的回文串了,有个细节注意的是, n计算完后要-1! 下面给出AC代码: 1 #include <bits/stdc++.h> 2 typedef long long ll; 3 using namespace std; 4 const int maxn=3010; 5

POJ2402/UVA 12050 Palindrome Numbers 数学思维

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). Additionallynumbers can of course be ordered in size. The ?rst few

UVA 12050 - Palindrome Numbers 模拟

题目大意:给出i,输出第i个镜像数,不能有前导0. 题解:从外层开始模拟 #include <stdio.h> int p(int x) { int sum, i; for(sum=i=1;i<=x;i++) sum *= 10; return sum; } int main() { int n, i, j, t, cs[1000], c; while(~scanf("%d", &n)) { if(n==0) break; i=1; while(n>9*

UVA - 12046 Great Numbers

Description Problem G - Great Numbers In this problem you have to count the number of great numbers of length n. Here a great number must have the following property: the number must be divisible by all of its decimal digits. it does not contain any

UVA - 471 Magic Numbers

Description  Magic Numbers  Write a program that finds and displays all pairs ofintegers and such that: neither nor have any digits repeated; and , where N is a given integer; Input and Output The input file consist a integer at the beginning indicat

UVa - 12050

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). Additionallynumbers can of course be ordered in size. The first fe

zoj2000 Palindrome Numbers

Palindrome Numbers Time Limit: 2 Seconds      Memory Limit: 65536 KB 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

Palindrome Numbers(LA2889)第n个回文数是?

 J - Palindrome Numbers Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVALive 2889 WA了一版面,我也是醉了,就因为一个编译环境不同...... 说多了都是泪. 题目链接:请点击UVALive 2889 转载请注明出处:寻找&星空の孩子 #include<stdio.h> #define LL lo

E - Palindrome Numbers

题目链接:https://vjudge.net/contest/237394#problem/E 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). Additionall

UVA 136 Ugly Numbers

原题代号:UVA 136 原题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=72 题目原题: Ugly Numbers Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence1, 2, 3, 4, 5,