Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define N 205
- using namespace std;
- ifstream fin("relatii.in");
- ofstream fout("relatii.out");
- int n, m,a[N],b[N], ap[12],viz[12];
- char s[5];
- int main()
- {
- int i,j,p;
- fin>>n>>m;
- for(i=1;i<=m;i++)
- {
- fin>>s;
- a[i]=s[0]-'a'+1;
- b[i]=s[2]-'a'+1;
- if(s[1]>='>') swap(a[i],b[i]);
- }
- for(j=1;j<=n;j++)
- {
- for(i=1;i<=n;i++)ap[i]=0;
- for(i=1;i<=m;i++)
- if(viz[b[i]]==0)ap[b[i]]=1;
- p=0;
- for(i=1;i<=n && p==0;i++)
- if(viz[i]==0 && ap[i]==0)p=i;
- viz[p]=1;
- fout<<(char)('a'+p-1);
- for(i=1;i<=m;i++)
- if(a[i]==p) a[i]=b[i]=0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement