n-1位數
n-1位數時間限製:3000 ms | 內存限製:65535 KB
難度:1
描述
已知w是一個大於10但不大於1000000的無符號整數,若w是n(n≥2)位的整數,則求出w的後n-1位的數。
輸入
第一行為M,表示測試數據組數。
接下來M行,每行包含一個測試數據。
輸出
輸出M行,每行為對應行的n-1位數(忽略前綴0)。如果除了最高位外,其餘位都為0,則輸出0。
樣例輸入
4
1023
5923
923
1000
樣例輸出
23
923
23
0
01.
#include <iostream>
02.
#include <cstring>
03.
using
namespace
std;
04.
05.
int
main()
06.
{
07.
int
n,k;
08.
int
testNum;
09.
10.
cin >> testNum;
11.
while
(testNum--)
12.
{
13.
unsigned
long
w;
14.
cin >> w;
15.
int
num[8];
16.
int
count = 1;
17.
while
(w)
18.
{
19.
num[count] = w % 10;
20.
w /= 10;
21.
count ++;
22.
}
23.
count -= 2;
24.
while
(num[count] == 0)
25.
--count;
//刪除前導0
26.
if
(count == 0)
27.
cout << 0 << endl;
28.
for
(
int
i = count; i >= 1; i--)
29.
cout << num[i];
30.
cout << endl;
31.
32.
33.
}
34.
35.
return
0;
36.
}
最後更新:2017-04-02 15:14:53