您的位置:首页 > 其它

UVA - 445 - Marvelous Mazes

2014-04-07 22:13 267 查看
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=386

题意:根据输入的字符串,解读成迷宫信息

解题:一开始用字符串来处理,测试OK,但WA;改用字符处理,直接AC。有时问题真得用字符来处理,又简单又高效!

#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
char ch;
int n = 0;
while ( (ch=cin.get()) != EOF )
{
if ( isdigit(ch) )
{
n += (ch-'0');
} // end if
else
{
if ( isalpha(ch) || ch=='*' )
{
if (ch == 'b') ch = ' ';
while ( n-- )
{
cout <<ch;
} // end while
n = 0;
} // end if
else
{
if ( ch == '!' || ch == '\n' )
{
cout <<endl;
} // end if
else
{
} // end else
} // end else
} // end else
} // end while
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: