Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- //#define MAX_SIZE 20
- int main(void){
- int input_data[20][20];
- int input_box[20][20];
- int data = 0;
- //first input
- int x = 0;
- int y = 0;
- int num_area = 0;
- //selected area data
- int x1; //x coordinate of left top
- int y1; //y coordinate of lef top
- int x2; //x coordinate of right bottom
- int y2; //x coordinate of right bottom
- //loop variable
- int i; //for x axis
- int j; //for y axis
- int k; //for collecting data
- scanf("%d %d %d", &x, &y, &num_area);
- //0 clear arrays
- for(j = 0; j < y; j++){
- for(i = 0; i < x; i++){
- input_data[i][j] = 0;
- input_box[i][j] = 0;
- //store data into array
- scanf("%d", &input_data[i][j]);
- }
- }
- //store data, * number of selected area
- for(k = 0; k < num_area; k++){
- //get the coordinates of the selected area
- scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
- //add the data of selected area
- for(j = y1-1; j <= y2-1; j++){
- for(i = x1-1; i <= x2-1; i++){
- data += input_data[i][j];
- //0 clear the used array so than not to add again
- input_data[i][j] = 0;
- }
- }
- }
- printf("%d\n", data);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement