阅读834 返回首页    go 阿里云 go 技术社区[云栖]


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

  上一篇:go 蛇形填 数
  下一篇:go 为什么我们会在互联网上爆粗不讲礼貌