主题:杭电2034题,高手赐教,这样编写为何通不过
#include<iostream>
#include<vector>
using namespace std;
template<class T>
void sort_elem(T first,T last)
{
T temp,temp1;
for(temp=first;temp!=last-1;temp++)
{
for(temp1=temp;temp1!=last-1;temp1++)
{
if(*temp1>*(temp1+1))
{
int tmp;
tmp=*temp1;
*temp1=*(temp1+1);
*(temp1+1)=tmp;
}
}
}
}
int main(void)
{
int n,m;
while(cin>>n>>m,n!=0 || m!=0)
{
if(n>=0 && n<=100 && m>=0 && m<=100)
{
vector<int>set1,set2;
int temp;
while(n--)
{
cin>>temp;
set1.push_back(temp);
}
while(m--)
{
cin>>temp;
set2.push_back(temp);
}
vector<int>::iterator ix1,ix2;
for(ix1=set1.begin();ix1!=set1.end();)
{
for(ix2=set2.begin();ix2!=set2.end();ix2++)
{
if(*ix1==*ix2)
{
ix1=set1.erase(ix1);
break;
}
}
if(ix2==set2.end())
{
ix1++;
}
}
if(!set1.empty())
{
sort_elem(set1.begin(),set1.end());
for(ix1=set1.begin();ix1!=set1.end();ix1++)
{
cout<<*ix1<<" ";
}
cout<<endl;
}
else
{
cout<<"NULL"<<endl;
}
}
}
return 0;
}
请高手详细解答
#include<vector>
using namespace std;
template<class T>
void sort_elem(T first,T last)
{
T temp,temp1;
for(temp=first;temp!=last-1;temp++)
{
for(temp1=temp;temp1!=last-1;temp1++)
{
if(*temp1>*(temp1+1))
{
int tmp;
tmp=*temp1;
*temp1=*(temp1+1);
*(temp1+1)=tmp;
}
}
}
}
int main(void)
{
int n,m;
while(cin>>n>>m,n!=0 || m!=0)
{
if(n>=0 && n<=100 && m>=0 && m<=100)
{
vector<int>set1,set2;
int temp;
while(n--)
{
cin>>temp;
set1.push_back(temp);
}
while(m--)
{
cin>>temp;
set2.push_back(temp);
}
vector<int>::iterator ix1,ix2;
for(ix1=set1.begin();ix1!=set1.end();)
{
for(ix2=set2.begin();ix2!=set2.end();ix2++)
{
if(*ix1==*ix2)
{
ix1=set1.erase(ix1);
break;
}
}
if(ix2==set2.end())
{
ix1++;
}
}
if(!set1.empty())
{
sort_elem(set1.begin(),set1.end());
for(ix1=set1.begin();ix1!=set1.end();ix1++)
{
cout<<*ix1<<" ";
}
cout<<endl;
}
else
{
cout<<"NULL"<<endl;
}
}
}
return 0;
}
请高手详细解答