题目:

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

这道题目就是要求你找出第n个回文序列数字,容易看出一位数的回文9种,二位数的回文9种,三位数的回文90种,四位数的回文90种,所以我们设一位数a[1]=9,a[2]=9后面就用一个函数得出来,a[i]=a[i-2]*10;规律容易,但是要想清楚怎么把一个个回文数字得出来,这题改bug改了两个来小时,最后别人提醒我可能数组开小了,然后才过了,值得后面再做几遍锻炼逻辑能力

#include <bits/stdc++.h>
using namespace std;
long long a[20];
int b[20];
void value(){a[1]=9,a[2]=9;for(int i=3;i<=19;){a[i]=a[i-2]*10;a[i+1]=a[i-1]*10;i+=2;}
}
int main()
{long long i,j,n,x,y,flag1,flag;value();while(cin>>n){if(n==0){break;}i=1,y=1;x=n;while(n>a[i]){n-=a[i];i++;}flag1=i;if((flag1)%2){flag=(flag1)/2+1;}else{flag=(flag1)/2;}b[1]=n*9/a[flag1];if((n*9)%a[flag1]){b[1]++;n-=(b[1]-1)*a[flag1]/9+1;}else{n-=(b[1]-1)*a[flag1]/9+1;}for(i=2;i<=flag;i++){y=1;for(j=2;j<=i;j++){y*=10;}b[i]=n/(a[flag1]/9/y)-1;if((n-(a[flag1]/9/y)*b[i])!=0){b[i]+=1;}n-=b[i]*(a[flag1]/9/y);}for(i=1;i<=flag;i++){cout<<b[i];}if(flag1%2){for(i=1;i<=flag-1;i++){cout<<b[flag-i];}}else{for(i=1;i<=flag;i++){cout<<b[flag-i+1];}}cout<<endl;
}return 0;
}

最后AC的感觉真爽

然后是一个ceil函数,头文件是#include<math.h>,这个函数感觉挺有用的,就是求一个数,大于等于这个数的最小整数值。

附上一个水题目加深印象。

A square number is an integer number whose square root is also an integer. For example 1, 4, 81 are some square numbers. Given two numbers a and b you will have to find out how many square numbers are there between a and b (inclusive).

Input

The input file contains at most 201 lines of inputs. Each line contains two integers a and b (0 < a ≤ b ≤ 100000). Input is terminated by a line containing two zeroes. This line should not be processed.

Output

For each line of input produce one line of output. This line contains an integer which denotes how many square numbers are there between a and b (inclusive).

Sample Input

1 4

1 10

0 0

Sample Output

2

3

这题就是给你两个数,让你求出两个数之间有可以开出整数平方根的数目。

#include<iostream>
#include<math.h>
using namespace std;
int main()
{long long n,x,m,y;while(cin>>n>>m){if(n==0&&m==0){break;}x=ceil(sqrt(n));y=sqrt(m);cout<<y-x+1<<endl;
}
return 0;
}

转载于:https://www.cnblogs.com/wangzhelin/p/9366290.html

思考题目,仔细检查,外加一个ceil函数相关推荐

  1. 洛谷B2029 大象喝水(附ceil函数写法)

    ## 题目描述 一只大象口渴了,要喝 $20$ 升水才能解渴,但现在只有一个深 $h$ 厘米,底面半径为 $r$ 厘米的小圆桶 ($h$ 和 $r$ 都是整数).问大象至少要喝多少桶水才会解渴. ** ...

  2. 程序员面试题目:请实现一个函数,把字符串中的每个空格替换成20。

    来源:我是码农,转载请保留出处和链接! 本文链接:http://www.54manong.com/?id=1223 题目:请实现一个函数,把字符串中的每个空格替换成"%20".例如 ...

  3. 【C语言习题】统计君君提水的桶数(不使用ceil函数与floor函数)

    题目内容:一只大象一天要喝20升水,而君君每次都会用一个深h厘米,底面半径为r厘米的圆桶(h和r都是整数,Pi=3.14159)为大象提水,请问君君要提多少桶水才能保证大象一天的喝水量. (提示:1L ...

  4. 利用map和reduce编写一个str2float函数,把字符串'123.456'转换成浮点数123.456:

    题目:利用map和reduce编写一个str2float函数,把字符串'123.456'转换成浮点数123.456: 来源:廖雪峰Python上的练习题 思路定位小数点,分割小数部分和整数部分,使用r ...

  5. Oracle PL / SQL – CEIL函数示例

    CEIL函数将指定的数字向上取整,并返回大于或等于指定数字的最小数字. CEIL功能示例 SELECT CEIL(1.2) FROM DUAL; -- output : 2SELECT CEIL(1. ...

  6. 编写一个C程序,实现以下功能:用一个函数实现两个字符串的比较,即自己写一个strcmp函数,函数原型为:int strcmp(char *p1,char *p2);设p1指向字符串s

    题目描述: 编写一个C程序,实现以下功能: 用一个函数实现两个字符串的比较,即自己写一个strcmp函数,函数原型为: int strcmp(char *p1,char *p2); 设p1指向字符串s ...

  7. python函数的组成要素_写好一个Python函数的六要素

    Python 虽然好用,但用好真的很难.尤其是函数部分,只要写不好,后面的一连串人都会遭殃.看又看不懂,测试起来也麻烦,维护又维护不动,真是让人头疼. 那怎么写好一个 Python 函数呢?<W ...

  8. PHP ceil()函数

    定义: ceil() 函数向上舍入为最接近的整数. 用于分页使用.获取页数. 语法: ceil(x) 返回不小于 x 的下一个整数,x 如果有小数部分则进一位.ceil() 返回的类型仍然是 floa ...

  9. 自己写一个strcmp函数(C++)

    题目说明: 写一个函数,实现两个字符串的比较.即自己写一个strcmp函数,函数原型为int strcmp( char * p1, char * p2); 设p1指向字符串s1,p2指向字符串s2.要 ...

最新文章

  1. 把有无线网卡的机子当作无线ap无需任何软件
  2. VB常用内部函数大全一览表(建议收藏)
  3. Html5 web本地存储
  4. java重载能否发生多次,java - 在Java中重载和多次调度 - SO中文参考 - www.soinside.com...
  5. 动力系统 —— 液压与气压
  6. vs code 开发企业级python_入股不亏!VS Code中最好用的Python扩展插件
  7. 给 Chrome浏览器 添加 Javascript小书签,查看当前页面全部加载的javascript文件及代码片段...
  8. Linux Netcat command – The swiss army knife of net
  9. 使用fiddler4和夜神模拟器进行app抓包
  10. 中国智慧建造行业投资前景分析与项目投资建议报告2021-2027年版
  11. mac 配置host
  12. 让计算机休眠的命令,电脑怎么取消休眠?关闭休眠命令是什么?
  13. AI反腐:细查24万份合同,牵出千亿违规采购
  14. SAP 未计划交货费-MIRO发票校验
  15. File 转 MultipartFile
  16. C语言编程集合A和B的交集,求两个递增链表A和B的交集,并将结果放在链表A中
  17. IDEA中新导入的项目找不到maven project解决办法
  18. LeetCode 第 58 场力扣夜喵双周赛(动态规划、马拉车算法,前后缀处理)/ 第 253 场力扣周赛(贪心,LIS)
  19. matlab如何导出表格图表,如何将matlab绘制的图表导入到Word中 | 我爱分享网
  20. 【rzxt.com】从四个角度判断本本屏幕好坏

热门文章

  1. JS实现的ajax发送数据重复
  2. 信息学奥赛一本通(C++)在线评测系统——基础(一)C++语言—— 1056:点和正方形的关系
  3. 【Linux】一步一步学Linux——fc命令(224)
  4. 【Linux】一步一步学Linux——rev命令(57)
  5. 【Linux】一步一步学Linux——Centos7.5安装图解(08)
  6. 【Vs2015】 常用字体的设置
  7. vector 查找_同样是Excel中的查找函数,这个函数却比VLOOKUP功能强100倍
  8. 逆向入门--第一次的HelloWorld
  9. 51nod 1414 冰雕 思路:暴力模拟题
  10. LVS(7)——NAT实践