Advertisement
Guest User

Сапер

a guest
Feb 11th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int main() {
  6.     freopen("input.txt","r",stdin);
  7.    
  8.     freopen("output.txt","w",stdout);
  9.     char map[12][30];
  10.     int r, c;
  11.     srand(time(0));
  12.    
  13.     for(r=0; r<12; r++){
  14.         for(c=0; c<30; c++){
  15.             map[r][c]= '.';
  16.         }
  17.     }
  18.    
  19.     for(r=0; r<10; r++){
  20.        
  21.         int a = rand()%12;
  22.         int b = rand()%30;
  23.         map[a][b] = '*';
  24.     }
  25.    
  26.  
  27.    
  28.     int count;
  29.     for(r=0; r<12; r++){
  30.         count=0;
  31.         for(c=0; c<30; c++){
  32.             if(map[r][c]=='.'){
  33.                 if(map[r-1][c-1]=='*' && r>0 && c>0) {
  34.                     count++;
  35.                 }
  36.                 if(map[r-1][c]=='*' && r>0){
  37.                     count++;
  38.                 }
  39.                 if(map[r-1][c+1]=='*' && r>0 && c<30-1){
  40.                     count++;
  41.                 }
  42.                 if(map[r][c+1]=='*' && c<30-1){
  43.                     count++;
  44.                 }
  45.                 if(map[r+1][c+1]=='*' && r<12-1 && c<30-1){
  46.                     count++;
  47.                 }
  48.                 if(map[r+1][c]=='*' && r<12-1){
  49.                     count++;
  50.                 }
  51.                 if(map[r+1][c-1]=='*' && c>0 && r<12-1){
  52.                     count++;
  53.                 }
  54.                 if(map[r][c-1]=='*' && c>0){
  55.                     count++;
  56.                 }
  57.                 if(count!=0){
  58.                     map[r][c]=count+'0';
  59.                     count=0;
  60.                 }
  61.             }
  62.         }
  63.        
  64.     }
  65.     for(r=0; r<12; r++){
  66.         for(c=0; c<30; c++){
  67.             printf("%c", map[r][c]);
  68.         }
  69.         printf("\n");
  70.     }
  71.    
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement