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;
}