Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int main() {
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- char map[12][30];
- int r, c;
- srand(time(0));
- for(r=0; r<12; r++){
- for(c=0; c<30; c++){
- map[r][c]= '.';
- }
- }
- for(r=0; r<10; r++){
- int a = rand()%12;
- int b = rand()%30;
- map[a][b] = '*';
- }
- int count;
- for(r=0; r<12; r++){
- count=0;
- for(c=0; c<30; c++){
- if(map[r][c]=='.'){
- if(map[r-1][c-1]=='*' && r>0 && c>0) {
- count++;
- }
- if(map[r-1][c]=='*' && r>0){
- count++;
- }
- if(map[r-1][c+1]=='*' && r>0 && c<30-1){
- count++;
- }
- if(map[r][c+1]=='*' && c<30-1){
- count++;
- }
- if(map[r+1][c+1]=='*' && r<12-1 && c<30-1){
- count++;
- }
- if(map[r+1][c]=='*' && r<12-1){
- count++;
- }
- if(map[r+1][c-1]=='*' && c>0 && r<12-1){
- count++;
- }
- if(map[r][c-1]=='*' && c>0){
- count++;
- }
- if(count!=0){
- map[r][c]=count+'0';
- count=0;
- }
- }
- }
- }
- for(r=0; r<12; r++){
- for(c=0; c<30; c++){
- printf("%c", map[r][c]);
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement