Created
January 3, 2016 17:36
-
-
Save LuxunHuang/6aa3e724a38a99ed16ea to your computer and use it in GitHub Desktop.
uva a10474
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void input_N ( int *N_array ){ | |
scanf("%d", N_array); | |
} | |
void input_Q ( int *Q_array ){ | |
scanf("%d", Q_array); | |
} | |
void bubble_sort_N ( int *N_array, int N){ | |
int * N_array_next; | |
int * N_array_next_next; | |
for(int i = N - 1; i > 0; i--){ | |
for(int j = 0; j < i; j++){ | |
N_array_next = N_array + j; | |
N_array_next_next = N_array_next + 1; | |
if( *N_array_next >= *N_array_next_next){ | |
*N_array_next += *N_array_next_next; | |
*N_array_next_next = *N_array_next - *N_array_next_next; | |
*N_array_next = *N_array_next - *N_array_next_next; | |
} | |
} | |
} | |
} | |
void search_Q ( int *N_array, int *Q_array, int Q, int N, int *spp){ | |
int *Q_array_next, *N_array_next, sp; | |
*spp += 1; | |
printf("CASE# %d:\n", *spp); | |
for( int i = 0; i < Q; i++){ | |
sp = 1; | |
Q_array_next = Q_array + i; | |
for( int j = 0; j < N; j++){ | |
N_array_next = N_array + j; | |
if( *Q_array_next == *N_array_next){ | |
printf("%d found at %d\n", *Q_array_next, j + 1); | |
sp = 0; | |
break; | |
} | |
} | |
if(sp == 1) printf("%d not found\n", *Q_array_next); | |
} | |
} | |
int main(){ | |
int N, Q, spp = 0; | |
int N_array[100], Q_array[100]; | |
while(scanf("%d %d", &N, &Q) && (N || Q)){ | |
printf("\n"); | |
for( int i = 0; i < N; i++){ | |
input_N( &N_array[0] + i); | |
} | |
printf("\n"); | |
for( int i = 0; i < Q; i++){ | |
input_Q( &Q_array[0] + i); | |
} | |
printf("\n"); | |
bubble_sort_N( &N_array[0], N); | |
search_Q( &N_array[0], &Q_array[0], Q, N, &spp); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
gcc -std=c11 -Wall -Wno-unused-value -Wno-unused-variable -g -o ./a10474 ./a10474.c | |
./a10474 | |
clear: | |
rm -rf ./a10474 | |
rm -rf ./a10474.dSYM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment