用C++写程序,下面有题目,在线等,谢谢

2025-04-13 00:14:24
推荐回答(2个)
回答1:

#include 
using namespace std;

int main()
{
int nCount = 0;
cin >> nCount;
int* arrData = new int[nCount]; // 存放所有数据
int nTmpData = 0;
bool bHadRepeat = false;
for (int i = 0; i < nCount; i++)
{
cin >> nTmpData;
arrData[i] = nTmpData;
int nRepeatCount = 0; // 重复数据个数
for (int j = 0; j < i; j++)
{
if (arrData[j] == nTmpData)
{
nRepeatCount++;
}
}
if (nRepeatCount == 1) // 说明有重复数据,且前面只输入了一次
{
if (true == bHadRepeat)
{
cout << " ";
// 前面已经输出了重复数据,后面再输出重复数据就加空格
}
cout << nTmpData;
bHadRepeat = true;
}
}

if (false == bHadRepeat)
{
cout << "None";
}
cout << endl;
return 0;
}


朋友,请【采纳答案】,您的采纳是我答题的动力,如果没有明白,请追问。谢谢。

回答2:

这个我可以做