求解3.28携程笔第二题,咋只过了0
```
#include
#include
#include
using namespace std;
int main()
{
int n, m;
int res = 0;
cin >> n >> m;
vector> v(n, vector(m));
// 切割字符串每一位为int
for (int i = 0; i < n; i++)
{
string t;
cin >> t;
for (int j = 0; j < m; j++)
v[i][j] = t[j]-'0';
}
// 逐行
for (int i = 0; i < n; i++)
{
for (int j = 0; j <= m-1; j+=2)
{
// 往后查2个 <<
if (j < m - 1)
{
if (v[i][j] != 1 || v[i][j + 1] != 1)
{
res++;
}
}
// 往后查1个
else if (j == m -1 && v[i][j] != 1)
{
res++;
}
}
}
cout << res;
return 0;
}
```
#include
#include
#include
using namespace std;
int main()
{
int n, m;
int res = 0;
cin >> n >> m;
vector
// 切割字符串每一位为int
for (int i = 0; i < n; i++)
{
string t;
cin >> t;
for (int j = 0; j < m; j++)
v[i][j] = t[j]-'0';
}
// 逐行
for (int i = 0; i < n; i++)
{
for (int j = 0; j <= m-1; j+=2)
{
// 往后查2个 <<
if (j < m - 1)
{
if (v[i][j] != 1 || v[i][j + 1] != 1)
{
res++;
}
}
// 往后查1个
else if (j == m -1 && v[i][j] != 1)
{
res++;
}
}
}
cout << res;
return 0;
}
```
全部评论
如果是1010的情况,你j+=2直接把0都跳过了,应该是j遇见0就往后移2位,计数器加一,否则往后移1位
相关推荐