NYOJ 96

 

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

View Code
 1 #include <stdio.h>
 2 #include <string.h>
 3 int main()
 4 {
 5      int n,m;
 6      scanf("%d%*c",&n);
 7      while(n--)
 8      {
 9           scanf("%*c%d",&m);
10           //自动忽略前导0 
11           printf("%d\n",m);
12           getchar();
13      }
14 }        
 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 using namespace std;
 5 
 6 int main()
 7 {
 8      int n,m;
 9      scanf("%d%*c",&n);
10      string s;
11      while(n--)
12      {
13           s.clear();
14           cin>>s;
15           s.erase(0,1);
16           while(s[0]=='0')
17           //不能是s[i++]=='0',因为执行erase后,长度自动减少,所以i无意意义 
18           {
19                s.erase(0,1);
20           }
21           if(s.size()==0)//否则1000这类的不会有输出 
22                cout<<0<<endl;
23           else
24                cout<<s<<endl;
25      }
26      return 0;
27 }        
原文地址:https://www.cnblogs.com/hxsyl/p/2677570.html