#include#include #include using namespace std;int main(){ int a[] = { 1,2,3,4,5,5,6,7,7,8,8,8,9,9,9,10,10 }; cout << a[0] << " "; for (int i = 1; i < 16; ++i) { if (a[i] == a[i - 1]&&a[i]==a[i+1])continue; else cout << a[i] << ' '; } system("pause"); return 0;}
通用解法2:
#include#include #include using namespace std;int main(){ int a[] = { 1,2,3,4,5,5,6,7,7,8,8,8,9,9,9,10,10 }; int n; cin >> n; for (int i = 0; i < n; ++i) cout << a[i] << ' '; for (int i = n; i < 17; ++i) { if (a[i] == a[i - n])continue; cout << a[i] << ' '; } system("pause"); return 0;}