Advertisement
Brick99

CCC01 Strategic Bombing

Apr 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. vector <string> a;
  8. bool flag=true;
  9.  
  10. void put(vector <bool> prov, char poc)
  11. {
  12.     if (flag == false) return;
  13.     if ( poc == 'B' )
  14.     {
  15.         flag=false;
  16.         return;
  17.     }
  18.  
  19.     for (int i=0;i<a.size();i++)
  20.     {
  21.         if ( poc == a[i][0] && prov[i] )
  22.         {
  23.             prov[i]=false;
  24.             put(prov,a[i][1]);
  25.         }
  26.     }
  27.     return;
  28. }
  29.  
  30. int main()
  31. {
  32.     char a1,a2;
  33.     cin>>a1>>a2;
  34.  
  35.     vector <string> ispis;
  36.  
  37.     while (a1!='*')
  38.     {
  39.         string t="";
  40.         t+=a1;t+=a2;
  41.         ispis.push_back(t);
  42.         a.push_back(t);t="";
  43.         t+=a2;t+=a1;
  44.         a.push_back(t);
  45.  
  46.         cin>>a1>>a2;
  47.     }
  48.  
  49.     vector <int> rj;
  50.  
  51.     for (int i=0;i<a.size();i++)
  52.     {
  53.         vector <bool> pr(a.size(),true);
  54.         pr[i]=false;
  55.         put(pr,'A');
  56.  
  57.         if (flag) rj.push_back(i);
  58.         else flag=true;
  59.     }
  60.  
  61.     for (int i=0;i<rj.size();i++)
  62.     {
  63.         char a1=a[rj[i]][0];
  64.         char a2=a[rj[i]][1];
  65.  
  66.         bool pro=true;
  67.         for (int j=0;j<ispis.size();j++)
  68.         if ( ispis[j][0] == a1 && ispis[j][1] == a2 ) { pro=false;break; }
  69.  
  70.         if ( pro ) cout<<a2<<a1<<endl;
  71.         else cout<<a1<<a2<<endl;
  72.     }
  73.     cout<<"There are "<<rj.size()<<" disconnecting roads."<<endl;
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement