1 条题解

  • 0
    @ 2025-8-24 21:18:14

    自动搬运

    查看原文

    来自洛谷,原作者为

    avatar Temp113
    You have full control over the entire world.

    搬运于2025-08-24 21:18:13,当前版本为作者最后更新于2025-03-25 20:25:58,作者可能在搬运后再次修改,您可在原文处查看最新版

    自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多

    以下是正文


    Solution

    可以使用 getline 输入一行。

    遍历。若为空格,记录之前的一字符串,统计此字符串。

    最后,排序并输出。

    Code

    #include<bits/stdc++.h>
    using namespace std;
    const int N = 205;
    int tot, l;
    string s, ss, a[N];
    int main(){
    	while(getline(cin, s)){
    		tot = 0;
    		l = s.length();
    		for(int i = 0; i < l; i++){
    			if(s[i] == ' '){
    				a[++tot] = ss;
    				ss = "";
    			}else ss += s[i];
    		}
    		if(ss != ""){
    			a[++tot] = ss;
    			ss = "";
    		}
    		sort(a + 1, a + tot + 1);
    		cout << tot << ' ';
    		for(int i = 1; i <= tot; i++) cout << a[i] << ' ';
    		cout << '\n';
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    11785
    时间
    1000ms
    内存
    512MiB
    难度
    2
    标签
    递交数
    0
    已通过
    0
    上传者