《天哪,C++11代码7*RE、2*WA、1*AC求助个位dalao神犇!!》
查看原帖
《天哪,C++11代码7*RE、2*WA、1*AC求助个位dalao神犇!!》
977778
__Harry_Haiyun__楼主2023/7/9 17:10
#include <bits/stdc++.h>
#define MOD 998244353
#define mod 1000000007
using namespace std;
int main()
{
	string chess[8];
	for (int i = 0; i < 8; i++)
	    cin >> chess[i];
    string chess2[8] = {"11111111",
                        "11111111",
                        "11111111",
                        "11111111",
                        "11111111",
                        "11111111",
                        "11111111",
                        "11111111"};
    for (int i = 0; i < 8; i++)
    {
        for (int j = 0; j < 8; j++)
        {
            int a = i,b = j;
            if (chess[i][j] == 'R')
            {
                for (int k = j + 1; k < 8; k++)
                {
                    if (chess[j][k] == '.') chess2[j][k] = '0';
                    else 
                    {
                        chess2[j][k] = '0';
                        break;
                    }
                }
                for (int k = j - 1; k >= 0; k--)
                {
                    if (chess[j][k] == '.') chess2[j][k] = '0';
                    else
                    {
                        chess2[j][k] = '0';
                        break;
                    }
                }
                for (int k = j + 1; k < 8; k++)
                {
                    if (chess[k][j] == '.') chess2[k][j] = '0';
                    else
                    {
                        chess2[k][j] = '0';
                        break;
                    } 
                }
                for (int k = j - 1; k >= 0; k++)
                {
                    if (chess[k][j] == '.') chess2[k][j] = '0';
                    else
                    {
                        chess2[k][j] = '0';
                        break;
                    }
                }
                chess2[i][j] = '0';
            }
            if (chess[i][j] == 'B')
            {
                for (int k = i; k >= 0; k--)
                {
                    if (chess[i - k][j - k] == '.')
                    {
                        chess2[i - k][j - k] = '0';
                        a--;
                        b--;
                    }
                    if (a == 0 || b == 0) break;
                }
                a = i;
                b = j;
                for (int k = i; k < 8; k++)
                {
                    if (chess[i + k][j + k] == '.')
                    {
                        chess2[i + k][j + k] = '0';
                        a--;
                        b--;
                    }
                    if (a == 0 || b == 0) break;
                }
                a = i;
                b = j;
                for (int k = i; k < 8; k++)
                {
                    if (chess[i + k][j - k] == '.')
                    {
                        chess2[i + k][j - k] = '0';
                        a--;
                        b--;
                    }
                    if (a == 0 || b == 0) break;
                }
                a = i;
                b = j;
                for (int k = i; k < 8; k++)
                {
                    if (chess[i - k][j + k] == '.')
                    {
                        chess2[i - k][j + k] = '0';
                        a--;
                        b--;
                    }
                    if (a == 0 || b == 0) break;
                }
                chess2[i][j] = '0';
            }
        }
    }
    for (int i = 0; i < 8; i++) cout << chess2[i] << endl;
	return 0;
}
2023/7/9 17:10
加载中...