Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CICLURI
- #include <iostream>
- #include <fstream>
- using namespace std;
- int a[100][100],n,C[100],cy;
- ifstream f("ciclu.in");
- using namespace std;
- void citire()
- {
- f >> n;
- for(int i=1;i<=n;i++)
- for(int j=1;j<=n;j++)
- f >> a[i][j];
- f >> cy;
- for(int i=1;i<=cy;i++)
- f >> C[i];
- }
- int verif()
- {
- for(int i=1;i<=cy-2;i++)
- for(int j=i+1;j<=cy;j++)
- if(C[i]==C[j]&&C[i+1]==C[j+1]||C[i]==C[j+1]&&C[i+1]==C[j])
- return 0;
- for(int i=1;i<cy;i++)
- if(a[C[i]][C[i+1]]!=1)
- return 0;
- if(C[1]!=C[cy])
- return 0;
- return 1;
- }
- int verif_ciclu_elementar()
- {
- for(int i=1;i<cy;i++)
- for(int j=i+1;j<cy;j++)
- if(C[i]==C[j])
- return 0;
- return 1;
- }
- int main()
- {
- citire();
- if(verif())
- {
- cout << "Ciclu";
- if(verif_ciclu_elementar())
- cout << " elementar";
- }
- else
- cout << "Nu ciclu";
- }
- LANTURI
- #include <iostream>
- #include <fstream>
- using namespace std;
- int a[100][100],n,L[100],ch;
- ifstream f("lant.in");
- void citire()
- {
- f >> n;
- for(int i=1;i<=n;i++)
- for(int j=1;j<=n;j++)
- f >> a[i][j];
- f >> ch;
- for(int i=1;i<=ch;i++)
- f >> L[i];
- }
- int verif_lantz()
- {
- for(int i=1;i<ch;i++)
- if(a[L[i]][L[i+1]]!=1)
- return 0;
- return 1;
- }
- int verif_lantz_elem()
- {
- for(int i=1;i<ch;i++)
- if(a[L[i]][L[i+1]]!=1)
- return 0;
- for(int i=1;i<ch;i++)
- for(int j=i+1;j<=ch;j++)
- if(L[i]==L[j])
- return 0;
- return 1;
- }
- int verif_lantz_simplu()
- {
- for(int i=1;i<ch;i++)
- if(a[L[i]][L[i+1]]!=1)
- return 0;
- for(int i=1;i<=ch-2;i++)
- if((L[i]==L[ch-1]&&L[i+1]==L[ch])||(L[i+1]==L[ch-1]&&L[i]==L[ch]))
- return 0;
- return 1;
- }
- int main()
- {
- citire();
- if(verif_lantz())
- cout << "Este lantz"<<endl;
- else
- cout << "Nu este lantz"<<endl;
- if(verif_lantz_elem())
- cout << "Este lantz elementar"<<endl;
- else
- cout << "Nu este lantz elementar"<<endl;
- if(verif_lantz_simplu())
- cout << "Este lantz simplu"<<endl;
- else
- cout << "Nu este lantz simplu"<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement