AC代码:
#include<iostream>
#include<iomanip>
#include<math.h>
#include<stdio.h>
#include <algorithm>
#include<vector>
#include<string>
using namespace std;
int main()
{
int n, i, k, count, x;
string ch;
char num[100] = {'\0'};
while (cin >> ch)
{
k = 0, count = 0, x = 0;
n = ch.size();
for (i = 0; i < n; i++)
{
if (ch[i] >= '0' && ch[i] <= '9') {
if (ch[i] == '0' && k == 0) {
k = 1;
continue;
}
else {
num[count++] = ch[i];
}
if (ch[i + 1] < '0' || ch[i + 1] > '9') {
if (x == 0) {
cout << num;
memset(num, '\0', sizeof(num));
x = 1, k = 0, count = 0;
}
else if (x == 1) {
cout << " " << num;
memset(num, '\0', sizeof(num));
k = 0, count = 0;
}
}
}
}
cout << endl;
}
return 0;
}