Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <string.h>
  4. #include <locale.h>
  5. #include <windows.h>
  6.  
  7. struct Box {
  8. int x, y, a;
  9. };
  10.  
  11. void inputDataForBox(struct Box* boxs, int N) {
  12. for (int i = 0; i < N; i++) {
  13. printf("Введите для %d квадрата координаты центра (x,y) и его длину: ", i+1);
  14. do {
  15. scanf_s("%d %d %d", &boxs[i].x, &boxs[i].y, &boxs[i].a);
  16. if (boxs[i].a <= 0) printf("Длина квадрата не может быть неположительной.\n");
  17. } while (boxs[i].a <= 0);
  18. }
  19. }
  20.  
  21. void printDataBox(struct Box* boxs, int N) {
  22. for (int i = 0; i < N; i++)
  23. printf("Квадрат N%d: координаты центра (%d, %d), длина стороны %d\n", i+1, boxs[i].x, boxs[i].y, boxs[i].a);
  24. }
  25.  
  26. int boxContentThePoint(struct Box box, int px, int py) {
  27. if ((box.x - box.a <= px) && (box.x + box.a >= px) && (box.y + box.a >= py) && (box.y - box.a <= py)) return 1;
  28. else return 0;
  29. }
  30.  
  31. int checkBoxContentOtherBox(struct Box firstBox, struct Box secondBox) {
  32. if (boxContentThePoint(firstBox, secondBox.x, secondBox.y)) {
  33. int leftXDownYCondition = boxContentThePoint(firstBox, secondBox.x - secondBox.a, secondBox.y - secondBox.a);
  34. int rightXDownYCondition = boxContentThePoint(firstBox, secondBox.x + secondBox.a, secondBox.y - secondBox.a);
  35. int leftXUpYCondition = boxContentThePoint(firstBox, secondBox.x - secondBox.a, secondBox.y + secondBox.a);
  36. int rightXUpYCondition = boxContentThePoint(firstBox, secondBox.x + secondBox.a, secondBox.y + secondBox.a);
  37. if ((leftXDownYCondition + rightXDownYCondition + leftXUpYCondition + rightXUpYCondition) == 4) return 1;
  38. else return 0;
  39. }
  40. else return 0;
  41. }
  42.  
  43. int square(struct Box box) {
  44. return pow(box.a, 2);
  45. }
  46.  
  47. void main() {
  48. setlocale(LC_ALL, "rus");
  49.  
  50. struct Box* boxs;
  51. int N;
  52.  
  53. printf("Введите количество квадратов: ");
  54. scanf_s("%d", &N);
  55.  
  56. boxs = (struct Box*)malloc(N * sizeof(struct Box));
  57.  
  58. inputDataForBox(boxs, N);
  59. printDataBox(boxs, N);
  60.  
  61. //printf("%d", boxContentThePoint(boxs[0], 3, 3));
  62. //printf("%d", checkBoxContentOtherBox(boxs[0], boxs[1]));
  63.  
  64. getchar();
  65. getchar();
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement