Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Se consideră un tablou bidimensional cu m linii şi n coloane (1≤m≤100, 1≤n≤100), ale cărui
- elemente aparţin mulţimii {0,1,2}. Scrieţi un program C/C++ citeşte de la tastatură valorile m,
- n şi elementele tabloului şi care afişează pe ecran numerele de ordine ale coloanelor pentru
- care produsul elementelor situate pe ele, este maxim. Liniile şi coloanele tabloului se
- numerotează de la 1 la m, respectiv de la 1 la n. Numerele se vor afişa separate prin câte
- un spaţiu.
- 5.
- Exemplu: pentru m=4 şi n=4 şi tabloul alăturat se va afişa:
- 1 2
- (10p.)
- 2 1 1 0
- 1 1 1 1
- 2 2 2 1
- 1 2 1 1
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int a[100][100],n,m,nr1,nr2,maxx;
- cin>>n>>m;
- for(int i=1;i<=n;i++)
- {
- for(int j=1;j<=m;j++)
- {
- cin>>a[i][j];
- maxx=-1;
- }
- }
- for(int j=1;j<=n;j++)
- {
- nr1=0;
- nr2=0;
- for(int i=1;i<=m;i++)
- {
- if(a[i][j]==0)
- {
- nr1++;
- }
- else
- {
- if(a[i][j]==2)
- {
- nr2++;
- }
- if(nr1>0)
- {
- a[0][j]=-1;
- }
- else
- {
- a[0][j]=nr2;
- }
- if(a[0][j]>maxx)
- {
- maxx=a[0][j];
- }
- }
- }
- }
- for(int j=1;j<=n;j++)
- {
- if(a[0][j]==maxx)
- {
- cout<<j<<" ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement