Advertisement
Anik_Akash

1514 - Contest

Nov 14th, 2020 (edited)
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.14 KB | None | 0 0
  1. //thanks God For Every Thing!
  2. //contest link:
  3. #include<bits/stdc++.h>
  4. #include <iostream>
  5. #include <fstream>
  6. #include <string>
  7. #include <algorithm>
  8. #include <cmath>
  9. #include <cstdlib>
  10. #define pi           (acos(-1.0)) //3.1415926535897932384626
  11. #define flush        cin.ignore(numeric_limits<streamsize>::max(),'\n');
  12. #define fasterio     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  13. #define NL           printf("\n")
  14. #define fin          freopen("int.txt","r",stdin);
  15. #define fout         freopen("out.txt","w",stdout);
  16.  
  17. using namespace std;
  18. typedef long long int ll;
  19. typedef double dl;
  20. typedef unsigned long long ul;
  21.  
  22. // ----------------------Pre made Functions---------------------------//
  23.  
  24. template <class T> T gcd(T a, T b){if(a == 0) return b;return gcd(b%a, a);}
  25. template <class T> T lcm(T a, T b){return ((a*b)/gcd(a, b));}
  26.  
  27.  
  28.  
  29. // ----------------------Slove---------------------------//
  30.  
  31. bool one_row(int arra[100][100]);
  32. bool all_one(int arra[100][100]);
  33. bool cal_one(int arra[100][100]);
  34. bool cal_zero(int arra[100][100]);
  35.  
  36. int n, m, i, j;
  37. int arra[100][100];
  38.  
  39. int main()
  40. {
  41.  
  42.     int ans=0;
  43.  
  44.     while(scanf("%d %d", &n, &m)!=EOF)
  45.     {
  46.         int c=0;
  47.         if(n==0 && m==0)
  48.             break;
  49.         else
  50.         {
  51.             for(i=0; i<n; i++)
  52.             {
  53.                 for(j=0; j<m; j++)
  54.                 {
  55.                     cin>>arra[i][j];
  56.                 }
  57.             }
  58.  
  59.            if(one_row(arra))
  60.                 c++;
  61.             if(all_one(arra))
  62.                 c++;
  63.             if(cal_one(arra))
  64.                 c++;
  65.             if(cal_zero(arra))
  66.                 c++;
  67.             cout<<c<<endl;
  68.         }
  69.     }
  70.     return 0;
  71. }
  72. bool one_row(int arra[100][100]) //find at least one 1 in every row;
  73. {
  74.     int cnt=0;
  75.     for(i=0; i<n; i++)
  76.     {
  77.         int l=0;
  78.         for(j=0; j<m; j++)
  79.         {
  80.             if(arra[i][j]!=0)
  81.                 l++;
  82.         }
  83.         if(l>0)
  84.             cnt++;
  85.     }
  86.     if(cnt==n)
  87.         return true;
  88.     else
  89.         return false;
  90. }
  91. bool all_one(int arra[100][100]) //check every row has at least one zero;
  92. {
  93.     int cnt=0;
  94.     for(i=0; i<n; i++)
  95.     {
  96.         int l=0;
  97.         for(j=0; j<m; j++)
  98.         {
  99.             if(arra[i][j]!=1)
  100.                 l++;
  101.         }
  102.         if(l>0)
  103.             cnt++;
  104.     }
  105.     if(cnt==n)
  106.         return true;
  107.     else
  108.         return false;
  109. }
  110. bool cal_one(int arra[100][100]) //check every cllum has at least one 1;
  111. {
  112.     int cnt=0;
  113.     for(i=0; i<m; i++)
  114.     {
  115.         int l=0;
  116.         for(j=0; j<n; j++)
  117.         {
  118.             if(arra[j][i]!=0)
  119.                 l++;
  120.         }
  121.         if(l>0)
  122.             cnt++;
  123.     }
  124.     if(cnt==m)
  125.         return true;
  126.     else
  127.         return false;
  128. }
  129. bool cal_zero(int arra[100][100]) //check every cllum has at least one 0;
  130. {
  131.     int cnt=0;
  132.     for(i=0; i<m; i++)
  133.     {
  134.         int l=0;
  135.         for(j=0; j<n; j++)
  136.         {
  137.             if(arra[j][i]!=1)
  138.                 l++;
  139.         }
  140.         if(l>0)
  141.             cnt++;
  142.     }
  143.     if(cnt==m)
  144.         return true;
  145.     else
  146.         return false;
  147. }
  148. //author: ANIKAKSH;
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement