P1320全部WA...求大佬帮忙
查看原帖
P1320全部WA...求大佬帮忙
528656
杰克老师楼主2023/10/7 15:24
// 洛谷P1320 压缩技术 
#include <iostream>
// 需要先从0开始判断 
// 注意是字符01, 不是整数01 
using namespace std;
string s;
string temp;
int main(){
	int n, cnt = 0;
	char num = '0'; 
	getline(cin, s);  // 输入第一行 
	n = s.length();  // 获取第一行的长度
	for (int i = 2; i <= n; i++){ // 输入剩余行数 
		getline(cin, temp);
		s.append(temp);
	} 
	cout << n; // 输出N 
	for (int i = 0; s[i] != '\0'; i++){ // 遍历字符串 
		if (s[i] == num){
			cnt++;
		}else{
			cout << " " << cnt;
			num = s[i];
			cnt = 1;
		}
	}
	cout << " " << cnt << endl;
	return 0;
}

大家好, DEV测试输入样例没有问题, 下载了第一个测试数据, 输出也没有问题, 但就是过不去... 求大佬指教

2023/10/7 15:24
加载中...