您的位置:首页 > 其它

ASCII Area UVA - 1641 WA原因总结(没有脑子

2018-02-23 17:15 232 查看
https://vjudge.net/problem/uva-1641
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n, w;

while(cin >> n >> w)
{
int cnt = 0;
string s;
for (int i = 1; i <= n; i++)
{
cin >> s;
bool flag = false;
for (int j = 0; j < w; j++)
{
if (s[j] == '/' || s[j] == '\\')
{
cnt++; flag = !flag;
}
else if (s[j] == '.'&&flag == true)
cnt += 2;
//	else if (s[j] == '\\' || s[j] == '/')
//{
//cnt++; flag = false;
//}
//否则永远不会跑到这个else if 来啊,一直就是true

}

}
cout << cnt / 2 << endl;//every time it++ or +2 and we know it must be % by 2
}
return 0;
}


《没有脑子》
WA不要钱的吗???
1  for循环里面用1很爽但是string是按照0开始的
2  最开始想的第一行只能是/\/\/\,其实完全没必要区分对待= =
结果每一行要么'/'要么'\\'(此处要用到转义字符)
3  Input
The input file contains several test cases, each of them as described below.
不看题的哦?有说了数据是好几行,写个while cin又不复杂,wa不要钱吗?
4 cnt/2就是cnt/2 不要有啥侥幸心理
5  不要特殊性,要普遍化
6 if (s[j] == '/' || s[j] == '\\')
else if (s[j] == '\\' || s[j] == '/')
这样的话肯定跑不到else if里面啊。。。
并且,可能有多个- 直接q=!q就好了(比flag还省了三个字母
否则你一直只是true跳不出去的!

其实你能想的出来。别怕 没有那么复杂

思维要开阔嘛。不要局限在样例
最后附赠
10 22
....... / \.... / \.......
.......\.\.. / . / .......
. / \ / \ / \ / . / ..\.\ / \ / \ / \.
.\.......\.. / ....... / .
..\.......\ / ....... / ..
.. / ................\..
. / ..................\.
.\ / \ / \ / \.. / \.. / \ / \ / \ / .
....... / . / ..\.\.......
.......\ / ....\ / .......
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: