UVa 113 Power of Cryptography
之前看到p值的範圍(10101),以為要做大數,實際上只要用double就行了,難度相當低的一題。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<cstdio> | |
#include<cmath> | |
int main() | |
{ | |
double n, p; | |
while (scanf("%lf %lf", &n, &p) == 2) | |
printf("%.0lf\n", pow(p, 1 / n)); | |
return 0; | |
} | |
請問一下板大喔
回覆刪除因為我幾乎都是用cin cout
而且剛接觸程社沒多久
我不太了解下面這句 ==2的這個地方是什麼意思
while(scanf("%lf %lf", &n, &p)==2)
可以說明一下嗎 謝謝喔~
如果你用cin的話,那寫 while( cin>>n>>p ) 就可以了。 我那樣寫是因為scanf 函數會回傳讀取成功的變數個數,所以n,p兩個變數都讀到的話,就會回傳2囉。
回覆刪除版主好:
回覆刪除可以請問如果是大數的話要怎麼做嗎
謝謝囉~