ZOJ的1002题，我试了很多输入但找不到错在哪里，在OJ上是WA，拜托大神们帮我看看

#include
using namespace std;

char* CreateMap(char map[][4],int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> map[i][j];
}
}
return *map;
}
void PrintMap(char map[][4], int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout<< map[i][j];
}
cout << endl;
}
}

bool Judge(char map[][4], int n,int i,int j) {
char m = map[i][j];
if (m == 'X' || m == 'O') return false;
if (m == '.') {
int p, q;
bool flag = true;
for (p = j-1; p >=0; p--) {
if (map[i][p] == 'O')flag = false;
if (map[i][p] == 'X')break;
}
for (p = j + 1; p < n; p++) {
if (map[i][p] == 'O')flag = false;
if (map[i][p] == 'X')break;
}
for (q = i - 1; q >= 0; q--) {
if (map[q][j] == 'O')flag = false;
if (map[q][j] == 'X')break;
}
for (q = i + 1; q < n; q++) {
if (map[q][j] == 'O')flag = false;
if (map[q][j] == 'X')break;
}
return flag;
}
}

int SearchMap(char map[][4],int n,int i,int j) {
bool flag;
int count = 0;
int p, q;
p = i;
for (q = j; q < n; q++) {
flag = Judge(map, n, p, q);
if (flag) {
map[p][q] = 'O';count++;
}
}
for (p = i + 1; p < n; p++) {
for (q = 0; q < n; q++) {
flag = Judge(map, n, p, q);
if (flag) {
map[p][q] = 'O'; count++;
}
}
}
return count;
}
void ReSet(char map[][4], int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (map[i][j] == 'O')map[i][j] = '.';
}
}
}

int MaxSearch(char map[][4], int n) {
int count = 0;
int j,h,k;
int i = 0;
for (j = 0; j < n; j++) {
int count2 = SearchMap(map, n, i, j);
ReSet(map, n);
if (count2 > count) {
count = count2; h = i; k = j;
}
}
return count;
}

int main() {
int n;
while (cin>>n&&n!=0) {
char map[4][4];
CreateMap(map, n);
int count = MaxSearch(map, n);
cout << count << endl;
}
return 0;
}

9个回答

wuli_Susu int main() { int n; vector<int> Count; cin >> n; while (n!=0) { char map[4][4]; CreateMap(map, n); int count = MaxSearch(map, n); Count.push_back(count); cin >> n; } int m = Count.size(); for (int i = 0; i < m; i++) { int o = Count[i]; cout << o << endl; } return 0; }我改成了这样，但还是错误，也包含了向量的头文件，。。。不知道

int main() {
int n;
cin>>n;
while (n!=0) {
char map[4][4];
CreateMap(map, n);
int count = MaxSearch(map, n);
cout << count << endl;
cin>>n;
}
return 0;
}

hany2008 cout<<Count.at(i)<<endl;试试吧

hany2008 可能是vector用的有问题，在for循环中输出时，采用cout<<

wuli_Susu wuli_Susu int main() { int n; vector<int> Count; cin >> n; while (n!=0) { char map[4][4]; CreateMap(map, n); int count = MaxSearch(map, n); Count.push_back(count); cin >> n; } int m = Count.size(); for (int i = 0; i < m; i++) { int o = Count[i]; cout << o << endl; } return 0; }我改成了这样，但还是错误，也包含了向量的头文件，。。。不知道

#include
#include
using namespace std;
char* CreateMap(char map[][4],int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> map[i][j];
}
}
return *map;
}
void PrintMap(char map[][4], int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout<< map[i][j];
}
cout << endl;
}
}
bool Judge(char map[][4], int n,int i,int j) {
char m = map[i][j];
if (m == 'X' || m == 'O') return false;
if (m == '.') {
int p, q;
bool flag = true;
for (p = j-1; p >=0; p--) {
if (map[i][p] == 'O')flag = false;
if (map[i][p] == 'X')break;
}
for (p = j + 1; p < n; p++) {
if (map[i][p] == 'O')flag = false;
if (map[i][p] == 'X')break;
}
for (q = i - 1; q >= 0; q--) {
if (map[q][j] == 'O')flag = false;
if (map[q][j] == 'X')break;
}
for (q = i + 1; q < n; q++) {
if (map[q][j] == 'O')flag = false;
if (map[q][j] == 'X')break;
}
return flag;
}
}
int SearchMap(char map[][4],int n,int i,int j) {
bool flag;
int count = 0;
int p, q;
p = i;
for (q = j; q < n; q++) {
flag = Judge(map, n, p, q);
if (flag) {
map[p][q] = 'O';count++;
}
}
for (p = i + 1; p < n; p++) {
for (q = 0; q < n; q++) {
flag = Judge(map, n, p, q);
if (flag) {
map[p][q] = 'O'; count++;
}
}
}
return count;
}
void ReSet(char map[][4], int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (map[i][j] == 'O')map[i][j] = '.';
}
}
}
int MaxSearch(char map[][4], int n) {
int count = 0;
int j,h,k;
int i = 0;
for (j = 0; j < n; j++) {
int count2 = SearchMap(map, n, i, j);
ReSet(map, n);
if (count2 > count) {
count = count2; h = i; k = j;
}
}
return count;
}
int main()
{ int n;
vector Count;
cin >> n;
while (n!=0)
{ char map[4][4];
CreateMap(map, n);
int count = MaxSearch(map, n);
Count.push_back(count);
cin >> n;
}
int m = Count.size();
for (int i = 0; i < m; i++)
{
cout <<Count.at(i) << endl;
}
return 0;
}

zoj ACM 1002题，运行显示runtime err
-

-
ZOJ1003 Crashing Balloon 新思路
-
ZOJ-1002 运行超时，求大神帮我看看应该怎么改！！跪谢~~
-
ZOJ 3890 Wumpus帮忙看下哪里错大牛们
-
ZOJ 1078 Palindrom Numbers
-
ZOJ Special AC String
-
Zoj4109 不知道为什么代码一直段错误，请大佬帮看看
-
C++ zoj 1004一道模拟堆栈的题目
-
zoj1178问一下各位哪里有问题为什么一直WA
-
zoj 1056 一道简单的acm，测试数据对，就是不通过 用的c++
-
ZOJ问题，提交总是不能全过
-
ZOJ2676最小割01规划问题
-
ZOJ 1003 crashing balloon 算法如何优化
-

-
zoj中的一道题目，编译错误，求大神指点？
-

-

-
ACM ZOJ 2283代码一直Segmentation Fault怎么回事
-

GitHub开源的10个超棒后台管理面板

100 个网络基础知识普及，看完成半个网络高手

C语言实现推箱子游戏

Java 的每个基本类型都对应了一个包装类型，比如说 int 的包装类型为 Integer，double 的包装类型为 Double。基本类型和包装类型的区别主要有以下 4 点。

8000字干货：那些很厉害的人是怎么构建知识体系的