From 81a2775dae49c06ba6aa146530d5682be0ce621f Mon Sep 17 00:00:00 2001 From: huatzy <56495508+huatzy@users.noreply.github.com> Date: Tue, 22 Oct 2019 18:00:09 +0800 Subject: [PATCH] Create Ex07_13.cpp --- 201816040201/Ex07_13.cpp | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 201816040201/Ex07_13.cpp diff --git a/201816040201/Ex07_13.cpp b/201816040201/Ex07_13.cpp new file mode 100644 index 0000000..b75b68e --- /dev/null +++ b/201816040201/Ex07_13.cpp @@ -0,0 +1,41 @@ +#include + +#include + +using namespace std; + + +int main() +{ + + array< int, 20> a1, a2;///a1为原始数组,a2为去重后的数组 + int sum = 0; + + for (int i = 0; i < 20; i++) + { + int x; + cin >> x; + if (x >= 10 && x <= 100)//数据合法 + a1[sum++] = x;;//输入原始数据 + } + int cnt = 0; + for (int i = 0; i < sum; i++)//去重 + { + + int flag = 0; + for (int j = i+1; j < sum; j++) + { + if (a1[i] == a1[j]) + flag = 1; + } + if (!flag) + a2[cnt++] = a1[i]; + + } + cout << cnt << endl;//一共有多少不同的数 + for (int i = 0; i < cnt; i++)//输出去重后的数组 + cout << a2[i] << ' '; + + return 0; + +}