文章

15

粉丝

27

获赞

0

访问

1.9k

头像
统计单词 题解:测试用例只有一个坑,别的很基本
P1394 华中科技大学
发布于2024年4月5日 08:42
阅读数 123

#include <bits/stdc++.h>
using namespace std;

int main(){
	string s;
	vector<string> sheet;
	while(cin>>s){
		sheet.push_back(s);
	}
	vector<int> ans;
	for(int i=0;i<sheet.size();i++){
		ans.push_back(sheet[i].size());
	}
	ans[ans.size()-1]--;
	for(const auto& x:ans){
		if(x==0)continue;
		else cout<<x<<" ";
	}
	cout<<endl;
	return 0;
}

解法为暴力解,直接读入所有的内容,认为用例中不存在,等其他符号,只存在空格,那么,只需要对结尾进行特殊处理,由于存在一个空格加。的情况 ,所以遇0不输出

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发