马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 798236606 于 2020-2-1 11:00 编辑
传送门:https://pintia.cn/problem-sets/9 ... /994805478658260992
解:#include<cstdio>
#include<cstring>
typedef struct BIGN{
int num[1000];
int len;
bool is_neg;
BIGN()
{
memset(num, 0, sizeof(num));
len = 0;
is_neg = false;
};
}bign;
bign str2bign(char *s)
{
bign a;
a.len = strlen(s);
if (s[0] == '-')
{
a.is_neg = true;
a.len--;
s++;
}
for (int i = 0; i < a.len; i++)
a.num[i] = s[a.len - 1 - i] - '0';
return a;
}
void print_bign(bign a)
{
if (a.is_neg)
putchar('-');
for (int i = a.len - 1; i >= 0; i--)
printf("%d", a.num[i]);
}
bign muti(bign a, int b)
{
bign c;
int carry = 0;
if (!b)
{
c.len++;
c.is_neg = a.is_neg;
return c;
}
if (a.is_neg + (b < 0) == 1)
c.is_neg = true;
if (b < 0)
b = -b;
for (int i = 0; i < a.len; i++)
{
int temp = a.num[i] * b + carry;
c.num[c.len++] = temp % 10;
carry = temp / 10;
}
while (carry)
{
c.num[c.len++] = carry % 10;
carry /= 10;
}
return c;
}
void is_per(bign a, bign b)
{
int hash_table[10] = {0};
for (int i = 0; i < a.len; i++)
hash_table[a.num[i]]++;
for (int i = 0; i < b.len; i++)
hash_table[b.num[i]]--;
for (int i = 0; i < 10; i++)
if (hash_table[i])
{
puts("No");
return;
}
puts("Yes");
}
int main(void)
{
char s[25];
scanf("%s", s);
bign a = str2bign(s), b = muti(a, 2);
is_per(a, b);
print_bign(b);
}
|