您的位置:首页 > 其它

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
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);
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: