UVA 10474 : https://uva.onlinejudge.org/external/104/10474.pdf
/*sort*/
#include <iostream>
#include<string.h>
#include <algorithm>
using namespace std;
int main() {
// your code goes here
int n=0,q=0;
int count = 1;
while(cin>>n>>q)
{
if(n==0&&q==0)break;
cout<<"CASE# "<<count<<":"<<endl;
int num[n];memset(num,0,sizeof(num));
int inquire[q];memset(inquire,0,sizeof(q));
for(int i=0;i<n;i++)
{
cin>>num[i];
}
sort(num,num+n);
for(int in=0;in<q;in++)
{
cin>>inquire[in];
}
for(int j =0;j<q;j++)
{
int check =0;
for(int k=0;k<n&&check==0;k++)
{
if(num[k]==inquire[j])
{
check =1;
cout<<inquire[j]<<" found at "<<++k<<endl;
}
}
if(check==0)
cout<<inquire[j]<<" not found"<<endl;
}
count++;
}
return 0;
}
/*sort*/
#include <iostream>
#include<string.h>
#include <algorithm>
using namespace std;
int main() {
// your code goes here
int n=0,q=0;
int count = 1;
while(cin>>n>>q)
{
if(n==0&&q==0)break;
cout<<"CASE# "<<count<<":"<<endl;
int num[n];memset(num,0,sizeof(num));
int inquire[q];memset(inquire,0,sizeof(q));
for(int i=0;i<n;i++)
{
cin>>num[i];
}
sort(num,num+n);
for(int in=0;in<q;in++)
{
cin>>inquire[in];
}
for(int j =0;j<q;j++)
{
int check =0;
for(int k=0;k<n&&check==0;k++)
{
if(num[k]==inquire[j])
{
check =1;
cout<<inquire[j]<<" found at "<<++k<<endl;
}
}
if(check==0)
cout<<inquire[j]<<" not found"<<endl;
}
count++;
}
return 0;
}
留言
張貼留言