Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void Do_Ureally_want_to(int arr[], int size);
- int main(){
- //freopen("input.txt","rt",stdin);
- //freopen("output.txt","wt",stdout);
- int marbles_n, queries,i,j,k__=1;
- scanf("%d%d",&marbles_n,&queries);
- do{
- int marblos[marbles_n], query[queries];
- for(i=0; i<marbles_n; i++)
- scanf("%d",&marblos[i]);
- Do_Ureally_want_to(marblos, marbles_n);
- for(i=0; i<queries; i++)
- scanf("%d",&query[i]);
- for(i=0; i<queries; i++){
- for(j=0; j<marbles_n; j++){
- if(query[i]==marblos[j])
- {
- i==0? (printf("CASE# %d:\n",k__))+(k__++):0;
- printf("%d found at %d\n",query[i],(j+1)); break;
- }
- else if((j+1) == marbles_n){
- i==0? (printf("CASE# %d:\n",k__))+(k__++):0;
- printf("%d not found\n",query[i]); break;
- }
- }
- }
- scanf("%d%d",&marbles_n,&queries);
- }while(queries!=0 && marbles_n!=0);
- }
- void Do_Ureally_want_to(int arr[], int size){
- int i,j,key;
- for(i=0; i<size; i++){
- key = arr[i];
- j = i-1;
- /*Move elements of arr[0..i-1], that are greater than key,
- to one position to the right.*/
- while(j>=0 && arr[j]>key){
- arr[j+1] = arr[j];
- j--;
- }
- arr[j+1] = key;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment