日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時間:2024/4/17 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 思考题目,仔细检查,外加一个ceil函数 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目:

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個回文序列數(shù)字,容易看出一位數(shù)的回文9種,二位數(shù)的回文9種,三位數(shù)的回文90種,四位數(shù)的回文90種,所以我們設(shè)一位數(shù)a[1]=9,a[2]=9后面就用一個函數(shù)得出來,a[i]=a[i-2]*10;規(guī)律容易,但是要想清楚怎么把一個個回文數(shù)字得出來,這題改bug改了兩個來小時,最后別人提醒我可能數(shù)組開小了,然后才過了,值得后面再做幾遍鍛煉邏輯能力

#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函數(shù),頭文件是#include<math.h>,這個函數(shù)感覺挺有用的,就是求一個數(shù),大于等于這個數(shù)的最小整數(shù)值。

附上一個水題目加深印象。

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

這題就是給你兩個數(shù),讓你求出兩個數(shù)之間有可以開出整數(shù)平方根的數(shù)目。

#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; }

?

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/wangzhelin/p/9366290.html

總結(jié)

以上是生活随笔為你收集整理的思考题目,仔细检查,外加一个ceil函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。