大数开方,结果不超过整型范围。我用的高精和二分在POJ通过了,在UVA没通过。后来在网上看到有大牛直接用double过了,实在让人佩服啊。
我的代码:
#include <stdio.h>
#include <string.h>
// 交换字符串函数
void swap_str(char str[]) {
int len = strlen(str);
for (int i=0; i<len/2; i++) {
int tmp = str[i];
str[i] = str[len-i-1];
str[len-i-1] = tmp;
}
}
// 大数与整型相乘函数(大数以字符串形式给出)
void my_mul(char str[], int x) {
int len = strlen(str);
int cp = 0, i, tmp;
swap_str(str);
for (i=0; i<len; i++) {
tmp = (str[i]-'0')*x + cp;
str[i] = (tmp%10) + '0';
cp = tmp / 10;
}
while (cp) {
str[i++] = (cp%10) + '0';
cp /= 10;
}
while ('0'==str[i-1] && i>1)
i--;
str[i