J - Palindrome Numbers

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

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

。。。。

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


 
  1. #include<stdio.h>
  2. #define LL long long
  3. #define MM 2000000000
  4. LL num[25]= {0};
  5. LL ppow(LL x,LL y)
  6. {
  7. LL tp=1;
  8. while(y--)
  9. {
  10. tp*=x;
  11. }
  12. return tp;
  13. }
  14.  
  15. void init()
  16. {
  17. LL tp=9,i;
  18. for(i=1;;)
  19. {
  20. num[i]=num[i-1]+tp;
  21. i++;//同行有多个i要处理的时候i,不要把i++放里面,由于变异环境不同。运算顺序不同,可能会wa
  22. num[i]=num[i-1]+tp;
  23. i++;
  24. tp=tp*10;
  25. if(num[i-1]>=MM)break;
  26. }
  27.  
  28. /* for(int i=1;i<21;i++)
  29. {
  30. LL p=(i+1)/2-1;
  31. num[i]=num[i-1]+9*ppow(10,p);
  32. // printf("%lld\n",num[i]);
  33. }
  34. // printf("%lld\n",num[0]);*/
  35. }
  36.  
  37. int main()
  38. {
  39. init();
  40. LL n;
  41. LL a[20];
  42. while(scanf("%lld",&n),n)
  43. {
  44. int len=0;
  45. for(int i=1; i<=20; i++)
  46. {
  47. if(n<=num[i])
  48. {
  49. len=i;
  50. break;
  51. }
  52. }
  53. // printf("len=%d\n",len);
  54. LL m=n-num[len-1];
  55. int l=(len+1)/2;
  56. // printf("m=%lld\tl=%d\n",m,l);
  57. LL ans=ppow(10,l-1)+m-1;
  58. // printf("ans=%lld\tppow=%lld\n",ans,ppow(10,l-1));
  59. printf("%lld",ans);
  60. if(len&1) ans/=10;
  61. while(ans)
  62. {
  63. printf("%lld",ans%10);
  64. ans/=10;
  65. }
  66. printf("\n");
  67. }
  68. return 0;
  69. }

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. DELPHI语法基础学习笔记-Windows 句柄、回调函数、函数重载等(Delphi中很少需要直接使用句柄,因为句柄藏在窗体、 位图及其他Delphi 对象的内部)

    函数重载重载的思想很简单:编译器允许你用同一名字定义多个函数或过程,只要它们所带的参数不同.实际上,编译器是通过检测参数来确定需要调用的例程.下面是从VCL 的数学单元(Math Unit)中摘录的一 ...

  2. linux 下vi中关于删除某段,某行,或者全部删除的命令

    1,先打开某个文件: vi   filename 2,转到文件结尾 在命令模式输入 G       转到10行 在命令模式输入 10G 4,删除所有内容:先用G 转到文件尾,然后使用下面命令: :1, ...

  3. ShareSDK第三方登陆 (IOS)

    1.http://www.mob.com/ 注册申请 2.http://www.mob.com/#/download SDK下载  (简洁版:http://www.mob.com/#/download ...

  4. Windows Service的安装卸载 和 Service控制

    原文 Windows Service的安装卸载 和 Service控制 本文内容包括如何通过C#代码安装Windows Service(exe文件,并非打包后的安装文件).判断Service是否存在. ...

  5. hdu4709求三角形面积

    Herding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  6. CentOS 6.4 x86_64 安装GCC 4.7.3

    下载gcc-4.7.3.tar.gz, 解压缩 wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.7.3/gcc-4.7.3.tar.gz tar -xzvf gcc-4.7. ...

  7. 引用iscroll的一个封装方法

    var Page = function(cid, data,callback) { var _self = this; var cid = $(cid); var currPage=1; // 下拉上 ...

  8. accept系统调用内核实现

    用户态对accept的标准使用方法: if ((client_fd = accept(sockfd, (struct sockaddr *)&remote_addr, &sin_siz ...

  9. shell telnet 路由器

    #!/usr/bin/expect -f spawn telnet 172.16.1.80 expect "login" { send "admin\n" ex ...

  10. autotools入门笔记(一)

    GNU autotools作用:收集系统配置信息并自动生成Makefile文件. GNU autotools主要包括三个工具:autoconf.automake.libtool,还有很多辅助的工具,包 ...