跳到正文

个人记录

6.14比赛分析-xiongsw

zdxfh约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟

版本

  1. v1当前

T619148 单词的长度

单词的长度网页

赛时代码

错误原因:不能把样例凑出来!!!

C++
#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
	getline(cin , s) ;
	int len=s.length();
	int temp=0;
	for(int i=0;i<len;i++)
	{
		if(s[i]==' ')
		{
			cout << temp-1<<',';
			temp=0;
		}
		temp++;
	}
	cout<<temp-1;
	return 0;
}

正解

C++
#include <bits/stdc++.h>
using namespace std;
bool b=false;
string s;
int main(){
	while(cin>>s){
		if(b){
			cout<<",";
		}else{
			b=true;
		}
		cout<<s.size();
	}
	return 0;
}
原文