题意:
定义新的表示数字的方式:
- 0 is represented by the empty set {}.
- For any number n > 0, n is represented by a set containing the representations of all non-negative integers smaller than n.
0 => {}
1 => {{}}
2 => {{},{{}}}
3 => {{},{{}},{{},{{}}}}
给出两个数,求它们的和(和不超过15)
思路:
字符串转数字方法:数字符 '{' 的个数n,那么这个数就是log2(n)。
两个数相加,再用递归输出答案。
代码:
#include <cstdio>
#include <cmath>
#include <cstring>
int t, n, count;
char c;
void print(int n)
{
if (n == 0)
{
printf("{}");
return;
}
printf("{");
printf("{}");
for (int i = 1; i < n; ++ i)
{
printf(",");
print(i);
}
printf("}");
}
int main()
{
scanf("%d", &t);
getchar();
while (t --)
{
n = 0;
count = 0;
while (true)
{
c = getchar();
if (c == '\n') break;
if (c == '{') count ++;
}
n += (int)(log2(count));
count = 0;
while (true)
{
c = getchar();
if (c == '\n') break;
if (c == '{') count ++;
}
n += (int)(log2(count));
print(n);
printf("\n");
}
}
本文探讨了一种独特的数字表示方式,通过特定符号组合来表示整数,并详细阐述了如何将这种表示转换为数值以及如何进行数值求和操作。
155

被折叠的 条评论
为什么被折叠?



