Advertisement
rotti321

Charlie

May 19th, 2021
1,061
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     ifstream cin("charlie.in");
  8.     ofstream cout("charlie.out");
  9.     int p,n,lung=2,lmax=-INT_MAX;
  10.     char s[100005];
  11.     cin>>p;
  12.     cin.ignore();
  13.     cin.getline(s,100005);
  14.     n=strlen(s);
  15.     if(p==1)
  16.     {
  17.         int i=0,j;
  18.         while(i<n)
  19.         {
  20.             j=i;
  21.             while(s[j]>s[j+1]&&s[j+1]<s[j+2]&&j+2<n)
  22.             {
  23.                 j=j+2;
  24.  
  25.             }
  26.             if(i!=j)
  27.             {
  28.                 lung=j-i+1;
  29.                 if(lung>lmax)
  30.                 {
  31.                     lmax=lung;
  32.                 }
  33.                 i=j;
  34.             }
  35.             i++;
  36.         }
  37.         cout<<lmax;
  38.     }
  39.     else if(p == 2)
  40.     {
  41.         int cont = 0;
  42.         char varf, ant, ch;
  43.         stack<char>steeva;
  44.         ant = s[0];
  45.         steeva.push(ant);
  46.         varf = s[1];
  47.         steeva.push(varf);
  48.         int pas = 2;
  49.         while(pas<=n)
  50.         {
  51.             ch = s[pas];
  52.             if(ant>varf && varf<ch)
  53.             {
  54.                 cont+=max(ant-'a'+1, ch-'a'+1);
  55.                 cout<<max(ant-'a'+1, ch-'a'+1)<<"#"<<varf<<endl;
  56.                 steeva.pop();
  57.                 steeva.push(ch);
  58.                 varf = ch;
  59.  
  60.             }
  61.             else{
  62.                 ant = varf;
  63.                 varf = ch;
  64.                 steeva.push(ch);
  65.                 pas++;
  66.  
  67.             }
  68.  
  69.  
  70.         }
  71.         cout<<cont;
  72.     }
  73.     return 0;
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement