这是完整的代码,
package spoj;
import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
public class ABSURD {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
String in = sc.nextLine();
long t = Long.parseLong(in);
while(t>0)
{
String n;
n = sc.nextLine();
int i= n.length()-1;
while(i>=0)
{
if(n.charAt(i) != '0')
break;
i--;
}
long k = Long.parseLong(n);
double x1 = (.95 * (double)k);
double x2 = (1.05*(double)k);
long x = (long)x1;
long y = (long)x2;
if((double)x == x1)
x = x-1;
System.out.println(x+" "+y);
n = n.substring(0,i+1);
// System.out.println(n);
if(n.equals(""))
{
System.out.println("not absurd");
t--;
continue;
}
String a = Long.toString(x);
int la = a.length();
String b = Long.toString(y);
int lb = b.length();
int absurdity = n.charAt(n.length()-1) == 5?2*n.length()-1:2*n.length();
//System.out.println(absurdity);
String answer = "not absurd";
if(n.length() == 1)
{
answer = "not absurd";
}
else
{
if(la<lb)
{
if(absurdity >2)
answer = "absurd";
}
if(lb == la)
{
int j=0;
while(j<la)
{
if(a.charAt(j) != b.charAt(j))
break;
j++;
}
int absurd = a.charAt(j)<'5' && b.charAt(j)>='5'?2*(j+1)-1:2*(j+1);
//System.out.println(absurd);
if(absurd<absurdity)
answer = "absurd";
}
}
System.out.println(answer);
t--;
}
}
}
问题是ABSURD。问题的链接是:http://www.spoj.com/problems/ABSURD/。我不知道它失败了哪个测试用例,尝试了很多。基本上,必须根据给定的规则减少尾随零并计算荒谬性。然后必须确定给定范围内是否存在一个整数,其荒谬性小于给定数字的荒谬性。
答案 0 :(得分:0)
我在您的代码中看到了一些潜在的错误。我不会在这里讨论它们,但会让你弄清楚自己(嗯,这就是练习的重点)。但是,我会给出一些代码发出错误结果的情况。我希望这能让你继续前进。