[算法导论] 卡牌II
作者:互联网
https://www.jb51.net/article/87237.htm
memset
memset 是重置
memcopy(b,a,n*sizeof(int))
a拷贝到b
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int main(){
int i=1;int n,q,t;
while(cin>>n>>q){ //卡牌张数,问题数
int card[n];
for(int k=0;k<n;k++){
cin>>card[k];
}
int cards[n];
memcpy(cards, card, n*sizeof(int)); //card赋值给cards
cout<<"Case #"<<i<<":"<<endl;
sort(cards,cards+n);
while(q--){
cin>>t;
int ix1=-1,ix2=-1;
for(int m=0;m<n;m++){ //ix1
if(card[m]==t){ ix1=m+1;break;}
}
for(int m=0;m<n;m++){ //ix2
if(cards[m]==t){ ix2=m+1;break;}
}
if(ix1!=-1){
cout<<t<<" from "<<ix1<<" to "<<ix2<<endl;
}else{
cout<<t<<" not found"<<endl;
}
}
i++;
}
}
标签:int,memset,导论,卡牌,II,cards,sizeof,include,card 来源: https://blog.csdn.net/Trance95/article/details/119150988