我有一题有问题,求助大佬!!
查看原帖
我有一题有问题,求助大佬!!
957640
Michelle01楼主2023/7/27 15:05

题号: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;
}

我的输出样例不对!!

2023/7/27 15:05
加载中...