1023 Have Fun with Numbers (20)
Posted yaxadu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1023 Have Fun with Numbers (20)相关的知识,希望对你有一定的参考价值。
#include<stdio.h> #include<string.h> struct bign { int d[21], len; bign() { memset(d, 0, sizeof(d)); len = 0; } }; bign change(char str[]) { bign a; a.len = strlen(str); for (int i = 0; i < a.len; i++) { a.d[i] = str[a.len - i - 1] - ‘0‘; } return a; } bign multi(bign a, int b) { bign c; int carry = 0; for (int i = 0; i < a.len; i++) { int temp = a.d[i] * b + carry; c.d[c.len++] = temp % 10; carry = temp / 10; } while (carry != 0) { //** c.d[c.len++] = carry % 10; carry /= 10; } return c; } bool Judge(bign a, bign c) { if (a.len != c.len) return false; int count[10] = { 0 }; for (int i = 0; i < a.len; i++) { count[a.d[i]]++; count[c.d[i]]--; } for (int i = 0; i < 10; i++) { if (count[i] != 0) return false; } return true; } int main() { char str[21]; scanf("%s", str); bign a = change(str); bign c = multi(a, 2); if (Judge(a, c) == true) printf("Yes "); else printf("No "); for (int i = c.len - 1; i >= 0; i--) { printf("%d", c.d[i]); } return 0; }
以上是关于1023 Have Fun with Numbers (20)的主要内容,如果未能解决你的问题,请参考以下文章
PAT 1023 Have Fun with Numbers
PAT 甲级 1023 Have Fun with Numbers