Michelle01 @ 2023-07-27 15:05:16
题号:U303676
我的代码
#include <stdio.h>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
using namespace std;
int main(){
string a[100];
string b[100];
int ans = 0;
int n, k;
cin >> n >> k;
bool p = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < n; i++){
if(a[i] != " "){
ans += a[i].size();
}
if(ans <= k){
if(p == 0){
cout << a[i] << " ";
}
if(p == 1){
cout << endl << a[i] << " ";
}
p = 0;
}
else{
cout << endl << a[i] << " ";
ans = 0;
p = 1;
}
}
return 0;
}
我的输出样例不对!!
by Michelle01 @ 2023-07-27 15:58:04
@cq_zry 3q3q明白了
by cq_zry @ 2023-07-27 15:58:12
@cq_zry 你把a[i]放到新的一行,a[i]的长度也要算的a