n-1位数

来源:互联网 发布:iphone健康刷步数软件 编辑:程序博客网 时间:2024/06/08 00:59

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。
样例输入
4102359239231000
样例输出
23923230
来源
[rooot]原创
上传者
rooot
问题分析:
分析题意即是让求从最高位下一位开始遇到的第一个非0数字到最后一个数字之间的数字。采用字符串处理比较方便。
代码: 
#include <iostream>#include <stdio.h> #include <string.h>#include <math.h>#include <vector>#include <queue>#include <stack>#include <map>#include <string>#include <algorithm>using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */int main(int argc, char** argv) {int m;scanf("%d",&m);while(m--){char input[8];scanf("%s",input);int length=strlen(input);for(int i=1;i<=length-1;i++){if(input[i] != '0' || i == length-1){printf("%s\n",&input[i]); break;}}}return 0;}



原创粉丝点击