Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int a[101][101];
- int gri[101],gre[101];
- int n,m;
- int x[101], lg;
- void CitireMA()
- {
- int i,j;
- ifstream f("graf1.txt");
- f>>n;
- for(i=1;i<=n;i++)
- {
- for(j=1;j<=n;j++)
- f>>a[i][j];
- }
- f.close();
- }
- void CitireMuc()
- {
- int i,x,y;
- ifstream g("graf2.txt");
- g>>n;
- g>>m;
- for(i=1;i<=m;i++) //while (!g.eof()) while (f>>x>>y)
- {
- g>>x>>y;
- a[x][y]=1;
- }
- g.close();
- }
- void VerifLantDrum()
- { int i,j,ok,s,d;
- cout <<endl;
- cout <<"Lungime lant/drum";
- cin >>lg;
- for(i=1;i<=lg;i++)
- cin >>x[i];
- ok=1;
- for(i=1;i<lg;i++)
- {
- s=x[i];d=x[i+1];
- // cout <<a[s][d]<<" ";
- if(a[s][d]==0 && a[d][s]==0)
- ok=0;
- }
- if(ok==1)
- {cout <<"E lant ";
- ok =1;
- for(i=1;i<lg;i++)
- for(j=i+1;j<=lg;j++)
- if (x[i]==x[j])
- ok=0;
- if(ok==1)
- cout <<"elem";
- else
- cout <<"Neelem,";
- }
- else
- cout <<"Nu e lant ";
- ok=1;
- for(i=1;i<lg;i++)
- {
- s=x[i];d=x[i+1];
- if(a[s][d]==0 )
- ok=0;
- }
- if(ok==1)
- {
- cout <<"E drum ";
- if(x[lg]==x[1]) // sau a[x[n]][x[1]] ==1
- cout <<"circuit ";
- }
- else
- cout <<"Nu e drum ";
- }
- void AfisareG()
- {
- int i,j;
- cout <<"Graf cu "<<n<<" noduri"<<endl;
- for(i=1;i<=n;i++)
- {
- for(j=1;j<=n;j++)
- {
- cout<<a[i][j]<<" ";
- }
- cout<<endl;
- }
- }
- void GradeExterioare()
- {
- int i,j;
- cout <<"Grade exterioare " ;
- for(i=1;i<=n;i++)
- {
- gre[i]=0;cout <<"Multimea + este ";
- for(j=1;j<=n;j++)
- { gre[i]=gre[i]+a[i][j];
- if(a[i][j]==1)
- cout <<j<<" ";
- }
- cout<<" gradul ext:" <<gre[i]<<" ";
- cout <<endl;
- }
- }
- void GradeInterioare()
- {
- int i,j;
- cout <<"Grade interioare " ;
- for(j=1;j<=n;j++)
- {
- gri[j]=0; cout <<"Multimea - este ";
- for(i=1;i<=n;i++)
- { gri[j]=gri[j]+a[i][j];
- if(a[i][j]==1)
- cout <<i<<" ";
- }
- cout<<" gradul int:" <<gri[j]<<" ";
- cout <<endl;
- }
- }
- int main()
- {
- int i;
- CitireMA();
- AfisareG();
- CitireMuc();
- AfisareG();
- GradeExterioare();
- GradeInterioare();
- VerifLantDrum();
- cout<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement