遇到字符串问题就头疼。最后用了指针才过。算是艰辛点了吧。
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
char str[150];
int main ( ) {
//freopen ( "input.txt", "r", stdin );
//freopen ( "output.txt", "w", stdout );
while ( ( gets ( str ) != NULL ) ) {
int i = 0;
char *s = str;
while ( *s != '\0' ) {
while ( *s >= '0' && *s <= '9' ) {
i += *s - '0';
s++;
}
if ( ( *s >= 'A' && *s <= 'Z' || *s == '*' ) || *s == 'b' ) {
while ( i > 0 ) {
if ( *s == 'b' ) printf ( " " );
else printf ( "%c", *s );
i--;
}
}
if ( *s == '!' ) printf ( "\n" );
s++;
}
printf ( "\n" );
}
}