7-1数据结构作业 #include <iostream> #include <vector> using namespace std; int main (){ int n,p; scanf("%d%d",&n,&p); vector<int> a(p,-1);//初始化数组,全为-1 while(n--){ int x; cin>>x; if(a[x%p]==-1)a[x%p]=x,cout<<x%p;//这个位置没有数就直接放进去 else{ int i = x%p; while(a[i]!=-1&&a[i]!=x){ i=(i+1)%p; }//有冲突的话就往后找 a[i]=x; cout<<i; } if(n>0)cout<<' '; } return 0; }
标签:cout,int,2023.12,x%,include,14 From: https://www.cnblogs.com/muzhaodi/p/17901950.html