程序代码:
#include <iostream>
using namespace std;
struct mystack
{
char buf[100];
unsigned size = 0;
};
bool push( mystack& s, char value )
{
if( value == 'C' )
{
s.size = 0;
return true;
}
if( s.size == sizeof(s.buf)/sizeof(*s.buf) )
return false;
s.buf[s.size++] = value;
return true;
}
bool pop( mystack& s, char& value )
{
if( s.size == 0 )
return false;
value = s.buf[--s.size];
return true;
}
int main( void )
{
unsigned n;
cin >> n;
mystack s;
for( unsigned i=0; i!=n; ++i )
{
char value;
cin >> value;
push( s, value );
}
int main( void )
{
unsigned n;
cin >> n;
mystack s = {};
for( unsigned i=0; i!=n; ++i )
{
char value;
cin >> value;
push( s, value );
}
if( s.size == 0 )
cout << "C ";
else
for( char value; pop(s,value); )
{
cout << value << ' ';
}
}
}
[此贴子已经被作者于2020-11-2 12:49编辑过]