test
原始文件为 cpp 代码,本文是转换后的 Markdown 文件。
#include <cstdio>
#include <iostream>
#include <cmath>
#include <math.h>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
bool save[32][32];
void draw(string input, int& index, int x, int y, int size)
{
// printf("draw(input, %d, %d, %d, %d)\n", index, x, y, size);
char ch = input[index++];
if(ch == 'p')
{
draw(input, index, x + size/2, y, size/2);
draw(input, index, x, y, size/2);
draw(input, index, x, y + size/2, size/2);
draw(input, index, x + size/2, y + size/2, size/2);
}else if(ch == 'f')
{
for(int i = x; i < x+size; ++i)
for(int j = y; j < y+size; ++j)
save[i][j] = true;
}
}
int main()
{
// freopen("in.txt", "r", stdin);
int T; scanf("%d", &T);
while(T--)
{
memset(save, false, sizeof(save));
string tree1, tree2;
cin >> tree1 >> tree2;
int index1 = 0; draw(tree1, index1, 0, 0, 32);
int index2 = 0; draw(tree2, index2, 0, 0, 32);
int cnt = 0;
for(int i = 0; i < 32; ++i)
for(int j = 0; j < 32; ++j)
if(save[i][j]) ++cnt;
printf("There are %d black pixels.\n", cnt);
}
}