偶然看到一道趣味題,將乙個正整數倒置
過來,例如,將1234變成4321。
如果採用c的話,使用do..while語句來做,只要temp不為0,每執行一次,rebmun用來存原整數的最右邊的數字並乘以10。**如下:
#include
<
stdio.h
>
void
main()
while
(temp);
printf (
"the number is: %d\n
",rebmun);
}我想了下,如果用python做的話
,那麼兩行就可以解決了x=
raw_input(
"enter the number:")
"the reversed number is %d"%int(x[::-1
])或者一句話風格:y=
lambda
x:int(str(x)[::-1
])
倒置乙個整數
倒置整數 比如 倒置前 int a 123654 倒置後 int a1 456321 public class test02 int result 0 儲存置換了位置的整數最後結果 int j len 下面的核心思想 通過for迴圈依次將每一數字按照位置乘以對應的10的j次冪 比如 第一位數字res...
將乙個正整數L隨機拆分成n個正整數
隨機指定範圍內n個不重複的數 最簡單最基本的方法 param min 指定範圍最小值 param max 指定範圍最大值 param n 隨機數個數 public static int randomcommon int min,int max,int n int result new int n i...
將乙個整數劃分為多個正整數之和
整數劃分問題是將乙個正整數n拆分成一組數連加並等於n的形式,顯然這組數中最大加數不大於n。令n為需要劃分的整數,m為劃分後的最大整數。例如將6劃分為最大加數為6的劃分形式如下 5 1 4 2,4 1 1 3 3,3 2 1,3 1 1 1 2 2 2,2 2 1 1,2 1 1 1 1 1 1 1 ...