A 牛牛爱字符串
题目地址:
基本思路:
根据题意模拟就行了,
但是要注意首先是输入有空格要用,
然后是数字可能很大,要用字符串方式储存,还有就是注意前导零,
细节还是挺多的,但是整体难度不大。
参考代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define IO std::ios::sync_with_stdio(false); cin.tie(0)
#define int long long
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define INF 0x3f3f3f3f
inline int read() {
int x = 0, neg = 1; char op = getchar();
while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
return neg * x;
}
inline void print(int x) {
if (x < 0) { putchar('-'); x = -x; }
if (x >= 10) print(x / 10);
putchar(x % 10 + '0');
}
const int maxn = 1e5 + 10;
char s[maxn];
signed main() {
while (gets(s)) {
int n = strlen(s);
string ans;
for (int i = 0; i < n; i++) {
if (isdigit(s[i])) {
bool v = false;
while (i < n && isdigit(s[i])) {
if (!v && s[i] == '0') {
i++;
continue;
}
v = true;
ans += s[i];
i++;
}
if (!v) cout << 0 << ' ';
else cout << ans << ' ';
i--;
ans = "";
}
}
cout << '\n';
}
return 0;
}
京公网安备 11010502036488号