20,不知问题在哪?
查看原帖
20,不知问题在哪?
1256608
Z09103839楼主2024/9/8 11:12
#include<iostream>
#include<string>
using namespace std;
int n,cnt=1;
int main() {
	//链接所有字符串
	string s,str;
	while (cin>>s) 	str += s;
	//输出矩阵长度
	n = sqrt(str.size());
	cout << n << ' ';
	//与上一个比较
	for (int i = 1; i < n * n; i++) {
		if (str[i]  == str[i-1])	cnt++;
		else {
			cout << cnt << ' ';
			cnt = 1;
		}
	}
	cout << cnt;
	return 0;
}

案例和我自己输入的数都能得到正确答案啊orz

2024/9/8 11:12
加载中...