0
下面是完整的代碼,不知道哪個邊界情況謬上SPOJ是給錯誤的答案
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--;
}
}
}
問題是荒謬的。鏈接到問題是:http://www.spoj.com/problems/ABSURD/。我不知道哪個測試用例失敗,嘗試了很多。基本上,必須根據給定的規則減少尾隨零並計算荒謬性。然後必須確定一個整數是否存在於給定範圍內,其荒謬性小於給定數的荒謬性。