給定兩個數字a和b,從^ b的右邊找到第k個數字?分別從a^b右邊找到第k位數字的輸出不符合預期?
我把4號作爲Input.First是測試cases.Then的數量,輸入是數字AB以及k:
鏈接的問題:
http://www.practice.geeksforgeeks.org/problem-page.php?pid=302
MyApproach (由空格分隔)。我計算出a^b,然後從右邊搜索每個數字,直到第k個數字不等於計數。如果我得到它們相等,則返回預期的剩餘數。
下面是代碼:
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
for(int i=1;i<=T;i++)
{
int count=1;
int a=sc.nextInt();
System.out.print(" ");
int b=sc.nextInt();
System.out.print(" ");
int k=sc.nextInt();
long result=(long) Math.pow(a,b);
if(k!=count)
{
while(k!=count)
{
count++;
int remainder=(int) (result%10);
result=result/10;
}
}
result=result%10;
System.out.println(result);
}
}
GeeksId Output:
Wrong !! Here your code Failed
Input:
7 6 3
And its Correct output is:
6
Eclipse的ID:
輸入:
輸出
Wny我在geeksId上失敗了嗎?我的解決方案是不是產生正確的輸出?
爲什麼我的回答出錯了。 –
@Jason arora你的程序是正確的,但是你的輸出行預先配置了兩個空格,GeeksforGeeks系統需要一個Integer作爲輸出,因此你的程序按照系統失敗。 解決方法: 註釋兩行, '// System.out.print(「」); ... // System.out.print(「」);' 和GFG系統將通過。 –
是的,你指出它的權利。你可以編輯代碼我的代碼你想說什麼?我需要評論的地方。 –