0
我不明白,为什么我的程序在此行中出现错误exc_bad_access code=exc_i386_gpflt
matrix[row].push_back(cell);
?为什么程序会出现错误exc_bad_access代码= exc_i386_gpflt
所以,我的代码:
#include <iostream>
#include <string>
#include <vector>
int calculate(int cell_1x1_price, int cell_1x2_price) {
if ((cell_1x1_price + cell_1x1_price) < cell_1x2_price) {
return cell_1x1_price + cell_1x1_price;
} else {
return cell_1x2_price;
}
}
int main() {
using std::cin;
using std::cout;
using std::string;
using std::vector;
int rows;
int columns;
int cell_1x2_price;
int cell_1x1_price;
cin >> rows >> columns >> cell_1x2_price >> cell_1x1_price;
vector<string> matrix;
matrix.reserve(rows);
char cell;
for (int row = 0; row < rows; ++row) {
for (int column = 0; column < columns; ++column) {
cin >> cell;
matrix[row].push_back(cell);
}
}
int sum = 0;
for (int row = 0; row < rows; ++row) {
for (int column = 0; column < columns; ++column) {
if (matrix[row][column] == '*') {
if (column + 1 < columns && matrix[row][column + 1] == '*') {
sum += calculate(cell_1x1_price, cell_1x2_price);
++column;
continue;
}
if (row + 1 < rows && matrix[row + 1][column] == '*') {
matrix[row + 1][column] = '.';
sum += calculate(cell_1x1_price, cell_1x2_price);
continue;
}
sum += cell_1x1_price;
}
}
}
cout << sum;
return 0;
}
关于什么做节目和投入:一是字符串包括4个整数:N,M,A,B(1≤N,M≤300,A,B≤1000 )。每个下一行包括M-符号。符号。是一个干净的单元格,*和**是脏的。
我需要找到清洗的总和,如果A的**单元格的总和,B是*的总和。