Advertisement
Guest User

Untitled

a guest
May 26th, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <stdio.h>
  2. //#define MAX_SIZE 20
  3.  
  4. int main(void){
  5. int input_data[20][20];
  6. int input_box[20][20];
  7. int data = 0;
  8.  
  9. //first input
  10. int x = 0;
  11. int y = 0;
  12. int num_area = 0;
  13.  
  14. //selected area data
  15. int x1; //x coordinate of left top
  16. int y1; //y coordinate of lef top
  17. int x2; //x coordinate of right bottom
  18. int y2; //x coordinate of right bottom
  19.  
  20. //loop variable
  21. int i; //for x axis
  22. int j; //for y axis
  23. int k; //for collecting data
  24.  
  25. scanf("%d %d %d", &x, &y, &num_area);
  26.  
  27. //0 clear arrays
  28. for(j = 0; j < y; j++){
  29. for(i = 0; i < x; i++){
  30. input_data[i][j] = 0;
  31. input_box[i][j] = 0;
  32.  
  33. //store data into array
  34. scanf("%d", &input_data[i][j]);
  35. }
  36. }
  37.  
  38. //store data, * number of selected area
  39. for(k = 0; k < num_area; k++){
  40.  
  41. //get the coordinates of the selected area
  42. scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
  43.  
  44. //add the data of selected area
  45. for(j = y1-1; j <= y2-1; j++){
  46. for(i = x1-1; i <= x2-1; i++){
  47. data += input_data[i][j];
  48.  
  49. //0 clear the used array so than not to add again
  50. input_data[i][j] = 0;
  51. }
  52. }
  53. }
  54.  
  55. printf("%d\n", data);
  56.  
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement