J - Palindrome Numbers

Time
Limit:
3000MS     Memory Limit:0KB     64bit
IO Format:
%lld & %llu

 
 
 
WA了一版面,我也是醉了,就由于一个编译环境不同。。

。。。。

 
说多了都是泪。
 
 
转载请注明出处:寻找&星空の孩子


 
#include<stdio.h>
#define LL long long
#define MM 2000000000
LL num[25]= {0};
LL ppow(LL x,LL y)
{
LL tp=1;
while(y--)
{
tp*=x;
}
return tp;
} void init()
{
LL tp=9,i;
for(i=1;;)
{
num[i]=num[i-1]+tp;
i++;//同行有多个i要处理的时候i,不要把i++放里面,由于变异环境不同。运算顺序不同,可能会wa
num[i]=num[i-1]+tp;
i++;
tp=tp*10;
if(num[i-1]>=MM)break;
} /* for(int i=1;i<21;i++)
{
LL p=(i+1)/2-1;
num[i]=num[i-1]+9*ppow(10,p);
// printf("%lld\n",num[i]);
}
// printf("%lld\n",num[0]);*/
} int main()
{
init();
LL n;
LL a[20];
while(scanf("%lld",&n),n)
{
int len=0;
for(int i=1; i<=20; i++)
{
if(n<=num[i])
{
len=i;
break;
}
}
// printf("len=%d\n",len);
LL m=n-num[len-1];
int l=(len+1)/2;
// printf("m=%lld\tl=%d\n",m,l);
LL ans=ppow(10,l-1)+m-1;
// printf("ans=%lld\tppow=%lld\n",ans,ppow(10,l-1));
printf("%lld",ans);
if(len&1) ans/=10;
while(ans)
{
printf("%lld",ans%10);
ans/=10;
}
printf("\n");
}
return 0;
}

Palindrome Numbers(LA2889)第n个回文数是?的更多相关文章

  1. POJ 2402 Palindrome Numbers(LA 2889) 回文数

    POJ:http://poj.org/problem?id=2402 LA:https://icpcarchive.ecs.baylor.edu/index.php?option=com_online ...

  2. POJ2402 Palindrome Numbers 回文数

    题目链接: http://poj.org/problem?id=2402 题目大意就是让你找到第n个回文数是什么. 第一个思路当然是一个一个地构造回文数直到找到第n个回文数为止(也许大部分人一开始都是 ...

  3. POJ2402 Palindrome Numbers第K个回文数——找规律

    问题 给一个数k,给出第k个回文数  链接 题解 打表找规律,详见https://www.cnblogs.com/lfri/p/10459982.html,差别仅在于这里从1数起. AC代码 #inc ...

  4. leetcode 9 Palindrome Number 回文数

    Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...

  5. [Swift]LeetCode479. 最大回文数乘积 | Largest Palindrome Product

    Find the largest palindrome made from the product of two n-digit numbers. Since the result could be ...

  6. leetcode-479-Largest Palindrome Product(找到两个乘数相乘得到的最大的回文数)

    题目描述: Find the largest palindrome made from the product of two n-digit numbers. Since the result cou ...

  7. 有趣的数-回文数(Palindrome number)

    文章转自http://blog.163.com/hljmdjlln@126/blog/static/5473620620120412525181/ 做LC上的题"Palindrome num ...

  8. leetcode4 Valid Palindrome回文数

    Valid Palindrome回文数 whowhoha@outlook.com Question: Given a string, determine if it is a palindrome, ...

  9. Palindrome 回文数

    回文数,从前到后,从后到前都一样 把数字转成字符串来处理 package com.rust.cal; public class Palindrome { public static boolean i ...

  10. Leetcode 3——Palindrome Number(回文数)

    Problem: Determine whether an integer is a palindrome. Do this without extra space. 简单的回文数,大一肯定有要求写过 ...

随机推荐

  1. Javascript 生成指定范围数值随机数

    JavaScript对随机数的介绍比较少,所以今天分享一下有关随机数的一些事儿.希望能对大家有点小帮助. 主要的公式就是parseInt(Math.random()*(上限-下限+1)+下限); Ma ...

  2. vs2010中将复制过来的文件或文件夹显示到解决方案管理

    今天在给一个做好的页面上加.net程序,我先将程序中的文件夹复制到解决方案中,可是在VS2010的解决方案资源管理器中并没有这样的文件夹,可明明 在这里,为什么显示不出来,应该在VS2010的哪个地方 ...

  3. [转]java-Three Rules for Effective Exception Handling

    主要讲java中处理异常的三个原则: 原文链接:https://today.java.net/pub/a/today/2003/12/04/exceptions.html Exceptions in ...

  4. MFC模板CArray及其派生类

    CArray及其派生类 1. 简介:访问方法及效率和普通的数组一样,比普通数组强大的功能是可以改变数组的大小.Array采用队列方式存储数据,因而其内部数据元素是以物理方式顺序排列的,所以检索.顺序执 ...

  5. Java面试宝典2014版

    一. Java基础部分......................................................................................... ...

  6. Effective C++_笔记_条款04_确定对象被使用之前已先被初始化

    (整理自Effctive C++,转载请注明.整理者:华科小涛@http://www.cnblogs.com/hust-ghtao/) 读取未初始化的值会导致不确定的行为.在某些平台上,仅仅只是读取为 ...

  7. Servlet的学习(三)

    本篇接上一篇<Servlet的学习(二)> ,主要讲诉如何使用MyEclipse来开发Servlet,和导入Servlet所需要的源代码. 现在我们来创建一个web应用,就叫[myserv ...

  8. Python Base64转码解码

    Python Base64 提供了好几种方法例如: encode, decode, encodestring, decodestring, b64encode, b64decode, standard ...

  9. 进程、线程、轻量级进程、协程和go中的Goroutine

    进程.线程.轻量级进程.协程和go中的Goroutine 那些事儿电话面试被问到go的协程,曾经的军伟也问到过我协程.虽然用python时候在Eurasia和eventlet里了解过协程,但自己对协程 ...

  10. CListCtrl插入数据避免闪烁

    1.锁定窗口,不进行刷新 m_list.LockWindowUpdate(); 2.设定列表不进行重画 m_list.SetRedraw(FALSE); 3.清空列表,删除历史数据 m_list.De ...