fork download
  1. #include <stdio.h>
  2.  
  3. int n, a[105][105], X[105],cot[105], cheo1[105], cheo2[105];
  4.  
  5. void Try(int i){
  6. for(int j = 1; j<= n; j++){
  7. if(cot[j] == 0 && cheo1[i-j+n] == 0 && cheo2[i+j-1] == 0){
  8. X[i] = j;
  9. cot[j] = 1, cheo1[i-j+n] = 1, cheo2[i+j-1] =1;
  10. if(i == n){
  11. for(int i = 1; i<=n; i++){
  12. for(int j = 1; j<= n; j++){
  13. if(X[i] == j){
  14. printf("Q");
  15. }
  16. else{
  17. printf(".");
  18. }
  19. }
  20. printf("\n");
  21. }
  22. printf("\n");
  23. }
  24. else{
  25. Try(i+1);
  26. }
  27. cot[j] = 0, cheo1[i-j+n] = 0, cheo2[i+j-1] = 0;
  28. }
  29. }
  30. }
  31. int main(){
  32. scanf("%d", &n);
  33.  
  34. Try(1);
  35. }
  36.  
Success #stdin #stdout 0s 5296KB
stdin
Standard input is empty
stdout
Standard output is empty