简单分型题
View Code
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std;
#define maxn 15
int n;
int power[maxn];
bool is(int a, int p)
{
while (p >= 0)
{
if (a / power[p] == 1)
return false;
a %= power[p];
p--;
}
return true;
}
void work()
{
int temp = 1;
for (int i = 0; i < power[n]; i++)
{
if (i >= power[temp] * 3)
temp++;
if (is(i, temp))
putchar('-');
else
putchar(' ');
}
putchar('\n');
}
int main()
{
//freopen("t.txt", "r", stdin);
power[0] = 1;
for (int i = 1; i <= 12; i++)
power[i] = power[i - 1] * 3;
while (scanf("%d", &n) != EOF)
work();
return 0;
}