HDU 1462(Word Crosses)

#include 
#include 
using namespace std;
const int MAXL = 15;
const int MAXN = 50;

char a[MAXL], b[MAXL], c[MAXL], d[MAXL];
char ans[MAXN][MAXN];

bool judge(char s1[], char s2[], int& p, int& q)
{
    for (int i = 0; s1[i]; i++)
    {
        for (int j = 0; s2[j]; j++)
        {
            if (s1[i] == s2[j])
            {
                p = i;
                q = j;
                return true;
            }
        }   
    }
    return false;
}

int main()
{
    int Case = 0;
    int p1, p2, p3, p4;
    while (cin >> a)
    {
        if (a[0] == '#')
            break;
        if (Case++ > 0)
            cout << endl;

        cin >> b >> c >> d;
        bool f1 = judge(a, b, p1, p2);
        bool f2 = judge(c, d, p3, p4);
        if (f1 == false || f2 == false)
            cout << "Unable to make two crosses" << endl;
        else
        {
            int t, len = strlen(a);
            for (int i = 0; i < MAXN; i++)
            {
                for (int j = 0; j < MAXN; j++)
                    ans[i][j] = ' ';
            }
            if (p2 < p4) 
            {
                t = p4;
                for (int i = 0; b[i]; i++)
                    ans[p4 - p2 + i][p1] = b[i];
                for (int i = 0; d[i]; i++)
                    ans[i][len + p3 + 3] = d[i];
            }
            else
            {
                t = p2;
                for (int i = 0; b[i]; i++)
                    ans[i][p1] = b[i];
                for (int i = 0; d[i]; i++)
                    ans[p2 - p4 + i][len + p3 + 3] = d[i];
            }

            for (int i = 0; a[i]; i++)
                ans[t][i] = a[i];
            for (int i = 0; c[i]; i++)
                ans[t][len + i + 3] = c[i];

            for (int i = 0; i < MAXN; i++)
            {
                int end = -1;
                for (int j = 0; j < MAXN; j++)
                    if (ans[i][j] != ' ')
                        end = j;
                for (int j = 0; j <= end; j++)
                    cout << ans[i][j];
                if (end != -1)
                    cout << endl;
            }
        }
    }
    return 0;
}

 

你可能感兴趣的:(HDU)