Skip to content

Instantly share code, notes, and snippets.

@tarcisio-marinho
Created October 25, 2016 04:38
Show Gist options
  • Save tarcisio-marinho/34fb74685ccd1318990ecc27ddd75604 to your computer and use it in GitHub Desktop.
Save tarcisio-marinho/34fb74685ccd1318990ecc27ddd75604 to your computer and use it in GitHub Desktop.
Permutação de números
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void swap(char *x, char *y){
char temp;
temp = *x;
*x = *y;
*y = temp;
}
void permute(char *a, int l, int r, int *answ){
int i;
if (l == r){
if(atoi(a) % 8 == 0){
(*answ)++;
}
}
else{
for (i = l; i <= r; i++){
swap((a+l), (a+i));
permute(a, l+1, r, answ);
swap((a+l), (a+i));
}
}
}
int main(){
int n_test, answ;
scanf("%d", &n_test);
int i;
for(i=1 ; i<=n_test ; i++){
answ=0;
char str[1000];
scanf("%s", str);
getchar();
int n;
n = strlen(str);
permute(str, 0, n-1, &answ);
if(answ != 0){
printf("YES\n");
}
else{
printf("NO\n");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment