Advertisement
Bowser17

Untitled

Sep 23rd, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. ///Se consideră un tablou bidimensional cu m linii şi n coloane (1≤m≤100, 1≤n≤100), ale cărui
  2. elemente aparţin mulţimii {0,1,2}. Scrieţi un program C/C++ citeşte de la tastatură valorile m,
  3. n şi elementele tabloului şi care afişează pe ecran numerele de ordine ale coloanelor pentru
  4. care produsul elementelor situate pe ele, este maxim. Liniile şi coloanele tabloului se
  5. numerotează de la 1 la m, respectiv de la 1 la n. Numerele se vor afişa separate prin câte
  6. un spaţiu.
  7. 5.
  8. Exemplu: pentru m=4 şi n=4 şi tabloul alăturat se va afişa:
  9. 1 2
  10. (10p.)
  11. 2 1 1 0
  12. 1 1 1 1
  13. 2 2 2 1
  14. 1 2 1 1
  15.  
  16. #include<bits/stdc++.h>
  17.  
  18. using namespace std;
  19.  
  20. int main()
  21. {
  22.     int a[100][100],n,m,nr1,nr2,maxx;
  23.     cin>>n>>m;
  24.     for(int i=1;i<=n;i++)
  25.     {
  26.         for(int j=1;j<=m;j++)
  27.         {
  28.             cin>>a[i][j];
  29.             maxx=-1;
  30.         }
  31.     }
  32.     for(int j=1;j<=n;j++)
  33.     {
  34.         nr1=0;
  35.         nr2=0;
  36.         for(int i=1;i<=m;i++)
  37.         {
  38.             if(a[i][j]==0)
  39.             {
  40.                 nr1++;
  41.             }
  42.             else
  43.             {
  44.                 if(a[i][j]==2)
  45.                 {
  46.                     nr2++;
  47.                 }
  48.                 if(nr1>0)
  49.                 {
  50.                     a[0][j]=-1;
  51.                 }
  52.                 else
  53.                 {
  54.                     a[0][j]=nr2;
  55.                 }
  56.                 if(a[0][j]>maxx)
  57.                 {
  58.                 maxx=a[0][j];
  59.                 }
  60.             }
  61.         }
  62.     }
  63.     for(int j=1;j<=n;j++)
  64.     {
  65.            if(a[0][j]==maxx)
  66.            {
  67.                 cout<<j<<" ";
  68.            }
  69.     }
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement