Keyword: ad hoc
Algorithm:
No special algorithm. Just scan the number and alphabet, and then print them.
Note:
1. The width of the output maze is not greater than 132. Eliminate the redundant.
2. Don't use "scanf %d", since you may encounter numbers like 10000000000001.
3. "b" should be " ".
4. Don't print a blank line at last.
Ah~ It's so difficult. :(
Code:
#include<cctype>
#include<iostream>
using namespace std;
void transform( int &n )
{
n = 0;
while( isdigit( cin.peek() ) )
n += cin.get() - '0';
}
int main()
{
char status;
int quant = 0, line = 0;
while( isprint( status = cin.peek() ) || status == '\n' )
if( isdigit( status ) )
{
transform( quant );
cin >> status;
if( line + quant > 132 )
quant = 132 - line;
line += quant;
if( status == 'b' )
status = ' ';
for( int i = 0; i < quant; ++i )
cout << status;
}
else if( status == '!' || status == '\n' )
{
cin.get();
cout << endl;
line = 0;
}
return 0;
}
沒有留言:
張貼留言