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是*的總和。