1147 -- 小周的烦恼
2015-08-31 16:58
148 查看
小周的烦恼
Time Limit:1000MS Memory Limit:65536K
Total Submit:139 Accepted:80
Description
4231 删去某位后可变成 423,421,431,231 其中最大的一个数为431。
小周想找到某个数删去某位后最大的一个数。请您帮帮他吧。
Input
输入第一行有一个整数N表示有N组测试数据。
接下来有N行,且每行都有一个整数m(0 < m < 2^30)。
Output
输出每行m删去某位后最大的一个数。
Sample Input
Sample Output
Hint
ahstu@icpc2014
Source
Time Limit:1000MS Memory Limit:65536K
Total Submit:139 Accepted:80
Description
4231 删去某位后可变成 423,421,431,231 其中最大的一个数为431。
小周想找到某个数删去某位后最大的一个数。请您帮帮他吧。
Input
输入第一行有一个整数N表示有N组测试数据。
接下来有N行,且每行都有一个整数m(0 < m < 2^30)。
Output
输出每行m删去某位后最大的一个数。
Sample Input
2 123 4231
Sample Output
23 431
Hint
ahstu@icpc2014
Source
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AK1147 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); while (n-- > 0) { int m = int.Parse(Console.ReadLine()); int[] a = new int[10]; int max = 0, len = (int)Math.Log10(m * 1.0) + 1, i, j, s; //Console.WriteLine(len); max = m / 10; for (i = len - 1; i >= 0; i--) { a[i] = m % 10; m /= 10; } for (i = 0; i < len; i++)//删除第i位,然后把这个数与max比较,遍历一遍得最大值 { s = 0; for (j = 0; j < len; j++) { if (i == j) continue; s = s * 10 + a[j]; } if (s > max) max = s; } Console.WriteLine(max); } } } }
相关文章推荐
- 1146 -- 结义兄弟
- 图片和byte的相互转换
- 重叠区间个数(算法)
- Hadoop第8周练习—Pig部署及统计访问日志例子
- Form表单基础知识和常用兼容方法笔记(一)
- HTML5 Geolocation(地理定位)用于定位用户的位置。
- spring整合webservice
- TCP/IP、Http、Socket的区别
- js快速排序
- 1145 -- ACMer
- 高效启动页(Splash) 推荐
- 1144 -- 光辉女郎之终极闪光
- Linux内核空间映射到用户空间
- The Memory Sinkhole
- 正则表达式之 JS 验证
- poj 3080 Blue Jeans
- C++动态数组使用方法
- Hadoop第7周练习—MapReduce进行数据查询和实现推简单荐系统
- 设计模式的依赖倒转原则再理解
- 设计模式(2):两条原则