1 条题解
-
0
按提题意模拟即可,遇到“->”就输出对应数量的空格。
需要注意数据中有几个字符串行末是有"->"的,处理不好的话就可能会越界、多输出或者少输出。
时间复杂度:
#include <iostream> #define endl '\n' using namespace std; using LL = long long; void solve(){ int n, k; cin >> n >> k; for(int i = 0; i < n; i++){ string s; cin >> s; int m = s.size(); for(int j = 0; j < m - 1; j++){ if(s[j] == '-' && s[j + 1] == '>'){ for(int t = 0; t < k; t++) cout << " "; j++; } else cout << s[j]; } if(!(s[m - 1] == '>' && s[m - 2] == '-')) cout << s[m - 1]; cout << endl; } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; cin >> T; while(T--){ solve(); } return 0; }
- 1
信息
- ID
- 2279
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 4
- 标签
- (无)
- 递交数
- 46
- 已通过
- 21
- 上传者