返回小组 开始 2026-03-07 13:00:00

3.7呈贡下午小测

结束 2026-03-07 15:00:00
Contest is over.
当前 2026-03-16 11:02:39

过滤

include<bits/stdc++.h>

using namespace std;

int main(){

string s, ans;
getline(cin, s);
bool pre_space = true; // 标记前一个字符是否是空格(初始为true,处理开头空格)
for(char c : s){
    if(c == ' '){
        pre_space = true; // 连续空格只标记,不加入结果
    }else{
        // 非空格字符:如果前一个是空格且结果非空,先加一个空格
        if(pre_space && !ans.empty()) ans += ' ';
        ans += c;
        pre_space = false;
    }
}
// 处理标点后必须有一个空格的情况(仅在标点后不是末尾/空格时补充)
int len = ans.size();
for(int i=0; i<len-1; i++){
    if((ans[i]==','||ans[i]=='.'||ans[i]==':') && ans[i+1]!=' '){
        ans.insert(i+1, " ");
        len++; // 插入后长度变化,更新
        i++;   // 跳过新增的空格,避免重复处理
    }
}
cout << ans << endl;
return 0;

}


zsyzsy  •  8天前

比赛已结束。