Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int isNearby(int distance, char element, char map[10][10], int height, int width, int y, int x) {
- --x;
- --y;
- if(distance == 0 && map[y][x] == element) {
- return 1;
- }
- int i;
- for(i = y - distance; i < y + distance; ++i) {
- if(i >= height || i < 0) {
- continue;
- }
- int j;
- for(j = x - distance; j < x + distance; ++j) {
- if(j >= width || j < 0) {
- continue;
- }
- if(map[i][j] == element) {
- return 1;
- }
- }
- }
- return 0;
- }
- int main(){
- int height, width, waterDistance, mountainDistance, sandDistance;
- int i, j;
- char water = '~';
- char mountain = 'A';
- char sand = 'X';
- FILE* input=fopen("be.txt", "r");
- fscanf(input, "%d %d %d", &waterDistance, &mountainDistance, &sandDistance);
- fscanf(input, "%d %d\n", &width, &height);
- printf("Maximal water distance: %d\nMaximal mountain distance: %d\nMinimal sand distance: %d\n", waterDistance, mountainDistance, sandDistance);
- char map[height][width];
- char line[20000];
- for (i=0;i<height;i++){
- fgets(line,200000,input);
- for(j=0;j<width;j++){
- map[i][j]=line[j];
- printf("%c",map[i][j]);
- }
- printf("\n");
- }
- fclose(input);
- int y, x;
- int count = 0;
- for(x = 1; x <= width; ++x) {
- for(y = 1; y <= height; ++y) {
- if(map[y][x] == mountain) {
- continue;
- }
- if(isNearby(waterDistance, water, map, height, width, y, x) == 1
- && isNearby(mountainDistance, mountain, map, height, width, y, x) == 1
- && isNearby(sandDistance, sand, map, height, width, y, x) != 1) {
- printf("%d|%d ---> %hc\n", x, y, map[y][x]);
- ++count;
- }
- }
- }
- printf("\n%d\n", count);
- //printf("%d\n", hely);
- /*
- FILE* output=fopen("ki.txt", "w");
- fprintf(output, "%d\n", hely);
- fclose(output);
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement