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. debian网易163更新服务器 源

    sudo vi /etc/apt/sources.list 加入如下内容即可: deb http://mirrors.163.com/debian/ jessie main non-free cont ...

  2. java class生成jar包(转)

    进入dos操作符窗口cd进入要打成jar包的class文件所有文件夹目录jar cvf [生成jar的名称.jar] [列出class文件] //若有多个,以空隔隔开 如:一.操作零散的单个或几个cl ...

  3. Java里的日期和时间学习

    Date date = new Date();//yyyy-mm-dd hh:mm:ss[.fffffffff] SimpleDateFormat sdf = new SimpleDateFormat ...

  4. UVA 322 ships (POJ 1138)

    题目地址: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  5. Swift - 同步请求获取网络数据

    使用NSURLConnection可以实现http通信.它提供了异步请求和同步请求两种通信方式. 注意:同步请求数据会造成主线程阻塞,必须请求结束后用户才能做其他的操作,所有通常在请求大数据或者网络不 ...

  6. 如何删除JAVA集合中的元素

    经常我们要删除集合中的某些元素.有些可能会这么写. public void operate(List list){ for (Iterator it = list.iterator(); it.has ...

  7. 使用MVC模式开发一简单的销售额查询系统

    与上一篇比较,只改变了index.jsp文件中form的提交路径 <form action="ShowServlet" method="post"> ...

  8. Delphi下用API代码创建Form

    program PMyWindowClass; uses  Windows,  Messages,  SysUtils; type  TMyWindow = class(TObject)  priva ...

  9. Android中View绘制优化之三---- 优化View

    本文原创, 转载请注明出处:http://blog.csdn.net/qinjuning 译三: 优化视图 关于如何设计自定义View以及响应触摸时间等,请看Android developer : 地 ...

  10. linux下nginx负载均衡部署

    nginx负载均衡部署 Nginx("engine x") 是一个高性能的 HTTP 和 反向代理 server,也是一个 IMAP/POP3/SMTP 代理server. Ngi ...