fork download
  1. /*
  2.  ============================================================================
  3.  Name : Bitmap.c
  4.  Author : harini
  5.  Version :
  6.  Copyright : Your copyright notice
  7.  Description : Hello World in C, Ansi-style
  8.  ============================================================================
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13.  
  14. struct node
  15. {
  16. int x;
  17. int y;
  18. struct node *next;
  19. }*head=NULL,*temp,*tail,*cur;
  20.  
  21. int r,c,i,j,k;
  22. int dirx[]={1,0,-1,0};
  23. int diry[]={0,1,0,-1};
  24. int mat[1000][1000],ans[1000][1000],flag[1000][1000];
  25.  
  26. //fn checks whether the next no is 1,,,and that elt is 0,,,returns 1 if true,,,
  27. /*int next(int **mat,int x1,int y1)
  28. {
  29. int x2,y2;
  30. if(mat[i][j]==0)
  31. {
  32. for(k=0;k<6;k++)
  33. {
  34. x2=i+dirx[k];
  35. y2=j+diry[k];
  36. if(x2<0 || x2>r || y2<0 || y2>c) continue;
  37. if(mat[x2][y2]==0) return 1;
  38. }
  39. }
  40. return 0;
  41. }*/
  42.  
  43. int nextans(int ans[1000][1000],int x1,int y1)
  44. {
  45. int x2,y2;
  46. if(ans[x1][y1]==0)
  47. {
  48. for(k=0;k<6;k++)
  49. {
  50. x2=x1+dirx[k];
  51. y2=y1+diry[k];
  52. if(x2<0 || x2>r || y2<0 || y2>c) continue;
  53. if(ans[x2][y2]==-1) continue;
  54. if(ans[x2][y2]==1) return 2;
  55. if(ans[x2][y2]==0) return 1;
  56. }
  57. }
  58. return 0;
  59. }
  60.  
  61. int bitmap()
  62. {
  63. scanf("%d %d",&r,&c);
  64. char matc[r][c];
  65. for(i=0;i<r;i++)
  66. for(j=0;j<c;j++)
  67. {
  68. flag[i][j]=0;
  69. ans[i][j]=-1;
  70. }
  71. for(i=0;i<r;i++)
  72. scanf("%s",matc[i]);
  73. for(i=0;i<r;i++)
  74. for(j=0;j<c;j++)
  75. {
  76. mat[i][j]=matc[i][j]-48;
  77. }
  78. /* for(i=0;i<r;i++)
  79. {
  80. for(j=0;j<c;j++)
  81. printf("%d\t",mat[i][j]);
  82. printf("\n");
  83. }*/
  84. //case1:if the element if 1
  85. int x2,y2;
  86. //printf("i=%d j=%d\n",i,j);
  87. for(i=0;i<r;i++)
  88. for(j=0;j<c;j++)
  89. {
  90. // printf("i=%d j=%d\n",i,j);
  91. if(mat[i][j]==1)// && !flag[i][j])
  92. {
  93. //printf("i=%d j=%d\n",i,j);
  94. flag[i][j]=1;
  95. ans[i][j]=0;
  96. //put all the adjacent elts to 1(int ans) if they are not 0(in mat)
  97. for(k=0;k<4;k++)
  98. {
  99. x2=i+dirx[k];
  100. y2=j+diry[k];
  101. if(x2<0 || y2<0 || x2>=r || y2>=c) continue;
  102. //printf("x2=%d y2=%d\n",x2,y2);
  103. if(mat[x2][y2]==1)
  104. {
  105. printf("x2=%d y2=%d mat val=1\n",x2,y2);
  106. ans[x2][y2]=0;
  107. flag[x2][y2]=1;
  108. }
  109. else
  110. {
  111. printf("x2=%d y2=%d mat val=0\n",x2,y2);
  112. ans[x2][y2]=1;
  113. flag[x2][y2]=1;
  114. }
  115. }
  116. }
  117. }
  118. //case2:element is 0,,,,and next element is one,,,
  119. /*if(next(mat,i,j) && !flag[i][j])
  120. {
  121. ans[i][j]=1;
  122. flag[i][j]=1;
  123. continue;
  124. }
  125. for(i=0;i<r;i++)
  126. for(j=0;j<c;j++)
  127. {
  128. if(!flag[i][j])
  129. {
  130. //if both case fails,,,we add to the stack,,,
  131. temp=(struct node*)malloc(sizeof(struct node));
  132. temp->x=0;
  133. temp->y=0;
  134. temp->next=NULL;
  135. if(head==NULL) head=temp;
  136. for(tail=head;tail->next!=NULL;tail=tail->next);
  137. tail->next=temp;
  138. if(nextans(ans,i,j)==1)
  139. ans[i][j]=1;
  140. else{
  141. */
  142. int n;
  143. for(i=0;i<r;i++)
  144. for(j=0;j<c;j++)
  145. if(!flag[i][j])
  146. {
  147. while((n=nextans(ans,i,j))!=0)
  148. {
  149. printf("i=%d j=%d",i,j);
  150. flag[i][j]=1;
  151. if(n==2) ans[i][j]+=2;
  152. if(n==1) ans[i][j]+=1;
  153. }
  154. }
  155. printf("\nFLAG\n");
  156. for(i=0;i<r;i++)
  157. {
  158. for(j=0;j<c;j++)
  159. printf("%d\t",flag[i][j]);
  160. printf("\n");
  161. }
  162. printf("\nANSWER,,,\n");
  163. for(i=0;i<r;i++)
  164. {
  165. for(j=0;j<c;j++)
  166. printf("%d\t",ans[i][j]);
  167. printf("\n");
  168. }
  169. return 0;
  170. }
  171.  
  172. int main()
  173. {
  174. int t;
  175. scanf("%d",&t);
  176. while(t-->0)
  177. {
  178. bitmap();
  179. //scanf("%d %d",&r,&c);
  180. //int ans[r][c];
  181.  
  182.  
  183. }
  184. return 0;
  185. }
  186. /*
  187.  ============================================================================
  188.  Name : Bitmap.c
  189.  Author : harini
  190.  Version :
  191.  Copyright : Your copyright notice
  192.  Description : Hello World in C, Ansi-style
  193.  ============================================================================
  194.  */
  195.  
  196. #include <stdio.h>
  197. #include <stdlib.h>
  198.  
  199. struct node
  200. {
  201. int x;
  202. int y;
  203. struct node *next;
  204. }*head=NULL,*temp,*tail,*cur;
  205.  
  206. int r,c,i,j,k;
  207. int dirx[]={1,0,-1,0};
  208. int diry[]={0,1,0,-1};
  209.  
  210. //fn checks whether the next no is 1,,,and that elt is 0,,,returns 1 if true,,,
  211. /*int next(int **mat,int x1,int y1)
  212. {
  213. int x2,y2;
  214. if(mat[i][j]==0)
  215. {
  216. for(k=0;k<6;k++)
  217. {
  218. x2=i+dirx[k];
  219. y2=j+diry[k];
  220. if(x2<0 || x2>r || y2<0 || y2>c) continue;
  221. if(mat[x2][y2]==0) return 1;
  222. }
  223. }
  224. return 0;
  225. }*/
  226.  
  227. int nextans(int ans[1000][1000],int x1,int y1)
  228. {
  229. int x2,y2;
  230. if(ans[x1][y1]==0)
  231. {
  232. for(k=0;k<6;k++)
  233. {
  234. x2=x1+dirx[k];
  235. y2=y1+diry[k];
  236. if(x2<0 || x2>r || y2<0 || y2>c) continue;
  237. if(ans[x2][y2]==-1) continue;
  238. if(ans[x2][y2]==1) return 2;
  239. if(ans[x2][y2]==0) return 1;
  240. }
  241. }
  242. return 0;
  243. }
  244.  
  245. int bitmap()
  246. {
  247. scanf("%d %d",&r,&c);
  248. int mat[r][c],ans[r][c],flag[r][c];
  249. char matc[r][c];
  250. for(i=0;i<r;i++)
  251. for(j=0;j<c;j++)
  252. {
  253. flag[i][j]=0;
  254. ans[i][j]=-1;
  255. }
  256. for(i=0;i<r;i++)
  257. scanf("%s",matc[i]);
  258. for(i=0;i<r;i++)
  259. for(j=0;j<c;j++)
  260. {
  261. mat[i][j]=matc[i][j]-48;
  262. }
  263. /* for(i=0;i<r;i++)
  264. {
  265. for(j=0;j<c;j++)
  266. printf("%d\t",mat[i][j]);
  267. printf("\n");
  268. }*/
  269. //case1:if the element if 1
  270. int x2,y2;
  271. //printf("i=%d j=%d\n",i,j);
  272. for(i=0;i<r;i++)
  273. for(j=0;j<c;j++)
  274. {
  275. // printf("i=%d j=%d\n",i,j);
  276. if(mat[i][j]==1)// && !flag[i][j])
  277. {
  278. //printf("i=%d j=%d\n",i,j);
  279. flag[i][j]=1;
  280. ans[i][j]=0;
  281. //put all the adjacent elts to 1(int ans) if they are not 0(in mat)
  282. for(k=0;k<4;k++)
  283. {
  284. x2=i+dirx[k];
  285. y2=j+diry[k];
  286. if(x2<0 || y2<0 || x2>=r || y2>=c) continue;
  287. //printf("x2=%d y2=%d\n",x2,y2);
  288. if(mat[x2][y2]==1)
  289. {
  290. printf("x2=%d y2=%d mat val=1\n",x2,y2);
  291. ans[x2][y2]=0;
  292. flag[x2][y2]=1;
  293. }
  294. else
  295. {
  296. printf("x2=%d y2=%d mat val=0\n",x2,y2);
  297. ans[x2][y2]=1;
  298. flag[x2][y2]=1;
  299. }
  300. }
  301. }
  302. }
  303. //case2:element is 0,,,,and next element is one,,,
  304. /*if(next(mat,i,j) && !flag[i][j])
  305. {
  306. ans[i][j]=1;
  307. flag[i][j]=1;
  308. continue;
  309. }
  310. for(i=0;i<r;i++)
  311. for(j=0;j<c;j++)
  312. {
  313. if(!flag[i][j])
  314. {
  315. //if both case fails,,,we add to the stack,,,
  316. temp=(struct node*)malloc(sizeof(struct node));
  317. temp->x=0;
  318. temp->y=0;
  319. temp->next=NULL;
  320. if(head==NULL) head=temp;
  321. for(tail=head;tail->next!=NULL;tail=tail->next);
  322. tail->next=temp;
  323. if(nextans(ans,i,j)==1)
  324. ans[i][j]=1;
  325. else{
  326. */
  327. int n;
  328. for(i=0;i<r;i++)
  329. for(j=0;j<c;j++)
  330. if(!flag[i][j])
  331. {
  332. while((n=nextans(ans,i,j))!=0)
  333. {
  334. printf("i=%d j=%d",i,j);
  335. flag[i][j]=1;
  336. if(n==2) ans[i][j]+=2;
  337. if(n==1) ans[i][j]+=1;
  338. }
  339. }
  340. printf("\nFLAG\n");
  341. for(i=0;i<r;i++)
  342. {
  343. for(j=0;j<c;j++)
  344. printf("%d\t",flag[i][j]);
  345. printf("\n");
  346. }
  347. printf("\nANSWER,,,\n");
  348. for(i=0;i<r;i++)
  349. {
  350. for(j=0;j<c;j++)
  351. printf("%d\t",ans[i][j]);
  352. printf("\n");
  353. }
  354. return 0;
  355. }
  356.  
  357. int main()
  358. {
  359. int t;
  360. scanf("%d",&t);
  361. while(t-->0)
  362. {
  363. bitmap();
  364. //scanf("%d %d",&r,&c);
  365. //int ans[r][c];
  366.  
  367.  
  368. }
  369. return 0;
  370. }
  371.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
2
5
7 7 2 11 7
10
9 1 7 6 9 9 8 7 6 7
compilation info
prog.cpp:199:8: error: redefinition of 'struct node'
 struct node
        ^
prog.cpp:14:8: error: previous definition of 'struct node'
 struct node
        ^
prog.cpp:204:3: error: conflicting declaration 'int* head'
 }*head=NULL,*temp,*tail,*cur;
   ^
prog.cpp:19:3: note: previous declaration as 'node* head'
 }*head=NULL,*temp,*tail,*cur;
   ^
prog.cpp:204:14: error: conflicting declaration 'int* temp'
 }*head=NULL,*temp,*tail,*cur;
              ^
prog.cpp:19:14: note: previous declaration as 'node* temp'
 }*head=NULL,*temp,*tail,*cur;
              ^
prog.cpp:204:20: error: conflicting declaration 'int* tail'
 }*head=NULL,*temp,*tail,*cur;
                    ^
prog.cpp:19:20: note: previous declaration as 'node* tail'
 }*head=NULL,*temp,*tail,*cur;
                    ^
prog.cpp:204:26: error: conflicting declaration 'int* cur'
 }*head=NULL,*temp,*tail,*cur;
                          ^
prog.cpp:19:26: note: previous declaration as 'node* cur'
 }*head=NULL,*temp,*tail,*cur;
                          ^
prog.cpp:206:5: error: redefinition of 'int r'
 int r,c,i,j,k;
     ^
prog.cpp:21:5: note: 'int r' previously declared here
 int r,c,i,j,k;
     ^
prog.cpp:206:7: error: redefinition of 'int c'
 int r,c,i,j,k;
       ^
prog.cpp:21:7: note: 'int c' previously declared here
 int r,c,i,j,k;
       ^
prog.cpp:206:9: error: redefinition of 'int i'
 int r,c,i,j,k;
         ^
prog.cpp:21:9: note: 'int i' previously declared here
 int r,c,i,j,k;
         ^
prog.cpp:206:11: error: redefinition of 'int j'
 int r,c,i,j,k;
           ^
prog.cpp:21:11: note: 'int j' previously declared here
 int r,c,i,j,k;
           ^
prog.cpp:206:13: error: redefinition of 'int k'
 int r,c,i,j,k;
             ^
prog.cpp:21:13: note: 'int k' previously declared here
 int r,c,i,j,k;
             ^
prog.cpp:207:10: error: redefinition of 'int dirx []'
 int dirx[]={1,0,-1,0};
          ^
prog.cpp:22:5: note: 'int dirx [4]' previously defined here
 int dirx[]={1,0,-1,0};
     ^
prog.cpp:208:10: error: redefinition of 'int diry []'
 int diry[]={0,1,0,-1};
          ^
prog.cpp:23:5: note: 'int diry [4]' previously defined here
 int diry[]={0,1,0,-1};
     ^
prog.cpp: In function 'int nextans(int (*)[1000], int, int)':
prog.cpp:227:5: error: redefinition of 'int nextans(int (*)[1000], int, int)'
 int nextans(int ans[1000][1000],int x1,int y1)
     ^
prog.cpp:43:5: note: 'int nextans(int (*)[1000], int, int)' previously defined here
 int nextans(int ans[1000][1000],int x1,int y1)
     ^
prog.cpp: In function 'int bitmap()':
prog.cpp:245:5: error: redefinition of 'int bitmap()'
 int bitmap()
     ^
prog.cpp:61:5: note: 'int bitmap()' previously defined here
 int bitmap()
     ^
prog.cpp:332:34: error: cannot convert 'int (*)[c]' to 'int (*)[1000]' for argument '1' to 'int nextans(int (*)[1000], int, int)'
          while((n=nextans(ans,i,j))!=0)
                                  ^
prog.cpp: In function 'int main()':
prog.cpp:357:5: error: redefinition of 'int main()'
 int main() 
     ^
prog.cpp:172:5: note: 'int main()' previously defined here
 int main() 
     ^
stdout
Standard output is empty