Advertisement
Anik_Akash

URI_1514_Contest

Jul 2nd, 2020
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.65 KB | None | 0 0
  1. //thanks God For Every Thing!
  2. //contest link: https://www.urionlinejudge.com.br/judge/en/problems/view/1514
  3. #include<bits/stdc++.h>
  4. #include<stdio.h>
  5. #include<math.h>
  6. #define pi                      acose(-1)
  7. #define rep(i,x)                for(int i=0; i<(x); i++)
  8. #define rep1(i,x)               for(int i=1; i<=(x); i++)
  9.  
  10. typedef long long int           ll;
  11. typedef double                  dl;
  12. using namespace std;
  13.  
  14. bool one_row(int arra[100][100]);
  15. bool all_one(int arra[100][100]);
  16. bool cal_one(int arra[100][100]);
  17. bool cal_zero(int arra[100][100]);
  18.  
  19. int n, m, i, j;
  20. int arra[100][100];
  21.  
  22. int main()
  23. {
  24.  
  25.     int ans=0;
  26.  
  27.     while(scanf("%d %d", &n, &m)!=EOF)
  28.     {
  29.         int c=0;
  30.         if(n==0 && m==0)
  31.             break;
  32.         else
  33.         {
  34.             for(i=0; i<n; i++)
  35.             {
  36.                 for(j=0; j<m; j++)
  37.                 {
  38.                     cin>>arra[i][j];
  39.                 }
  40.             }
  41.  
  42.            if(one_row(arra))
  43.                 c++;
  44.             if(all_one(arra))
  45.                 c++;
  46.             if(cal_one(arra))
  47.                 c++;
  48.             if(cal_zero(arra))
  49.                 c++;
  50.             cout<<c<<endl;
  51.         }
  52.     }
  53.     return 0;
  54. }
  55. bool one_row(int arra[100][100]) //find at least one 1 in every row;
  56. {
  57.     int cnt=0;
  58.     for(i=0; i<n; i++)
  59.     {
  60.         int l=0;
  61.         for(j=0; j<m; j++)
  62.         {
  63.             if(arra[i][j]!=0)
  64.                 l++;
  65.         }
  66.         if(l>0)
  67.             cnt++;
  68.     }
  69.     if(cnt==n)
  70.         return true;
  71.     else
  72.         return false;
  73. }
  74. bool all_one(int arra[100][100]) //check every row has at least one zero;
  75. {
  76.     int cnt=0;
  77.     for(i=0; i<n; i++)
  78.     {
  79.         int l=0;
  80.         for(j=0; j<m; j++)
  81.         {
  82.             if(arra[i][j]!=1)
  83.                 l++;
  84.         }
  85.         if(l>0)
  86.             cnt++;
  87.     }
  88.     if(cnt==n)
  89.         return true;
  90.     else
  91.         return false;
  92. }
  93. bool cal_one(int arra[100][100]) //check every cllum has at least one 1;
  94. {
  95.     int cnt=0;
  96.     for(i=0; i<m; i++)
  97.     {
  98.         int l=0;
  99.         for(j=0; j<n; j++)
  100.         {
  101.             if(arra[j][i]!=0)
  102.                 l++;
  103.         }
  104.         if(l>0)
  105.             cnt++;
  106.     }
  107.     if(cnt==m)
  108.         return true;
  109.     else
  110.         return false;
  111. }
  112. bool cal_zero(int arra[100][100]) //check every cllum has at least one 0;
  113. {
  114.     int cnt=0;
  115.     for(i=0; i<m; i++)
  116.     {
  117.         int l=0;
  118.         for(j=0; j<n; j++)
  119.         {
  120.             if(arra[j][i]!=1)
  121.                 l++;
  122.         }
  123.         if(l>0)
  124.             cnt++;
  125.     }
  126.     if(cnt==m)
  127.         return true;
  128.     else
  129.         return false;
  130. }
  131. //author: ANIKAKSH;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement