DS_T_code_2.2_T6

版权声明:转载请注明出处 https://blog.csdn.net/chushoufengli/article/details/83147496
#include <cstdio>
#include <iostream>
using namespace std;
const int MAXN = 1010;
struct l {
	int data[MAXN];
	int length = 0;
} L;
bool solve(l& L) {
	int s = 0;
	int k = 0;
	int pre = L.data[0];
	for(int i=1; i<L.length; i++) {
		if(L.data[i] == pre) {
			k++;
			L.data[i - k] = L.data[i];
			printf("\n >>> %d <<< \n",k);
		} else {
			k = 0;
			s += k;
		}
		pre = L.data[i];
	}
	L.length -= s;
	return true;
}
int main() {
	//输入
	scanf("%d",&L.length);
	int x_1;
	for(int i=0; i<L.length; i++) {
		scanf("%d",&x_1);
		L.data[i] = x_1;
	}
	//solve
	if(solve(L)) {
		for(int i=0; i<L.length; i++) {
			printf("%d ",L.data[i]);
		}
	} else printf("失败");
	return 0;
}
//1 2 2 2 3


猜你喜欢

转载自blog.csdn.net/chushoufengli/article/details/83147496
T