Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment_02 #149

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions 201816040312/Ex07_13.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
#include<iomanip>
#include<array>
using namespace std;

int main()
{
array<int,20> a;//创建数组
cout<<"请输入数组的值:";
int i;

for(i=0;i<20;++i)//初始化数组
{
cin>>a[i];
int j;
for(j=0;j<i;++j)
{
if(a[i]==a[j])
a[i]=0;
}
}
for(i=0;i<20;++i)//输出数组内容
{
if(a[i]==0)
continue;
else
cout<<setw(5)<<a[i];
}
}
30 changes: 30 additions & 0 deletions 201816040312/Ex07_14.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <iostream>
#include<iomanip>
#include<vector>
using namespace std;

int main()
{
vector<int> a(0);
int i,b,k;
int flag,t=0;

while(t<20)
{
flag=0;
cin>>b;
k=a.size();
for(i=0;i<k;i++)
{
if(b==a[i])
flag=1;
}
if(flag==0)
a.push_back(b);
t++;

}
for(int an:a)
cout<<an<<setw(5);

}