Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- ifstream cin("charlie.in");
- ofstream cout("charlie.out");
- int p,n,lung=2,lmax=-INT_MAX;
- char s[100005];
- cin>>p;
- cin.ignore();
- cin.getline(s,100005);
- n=strlen(s);
- if(p==1)
- {
- int i=0,j;
- while(i<n)
- {
- j=i;
- while(s[j]>s[j+1]&&s[j+1]<s[j+2]&&j+2<n)
- {
- j=j+2;
- }
- if(i!=j)
- {
- lung=j-i+1;
- if(lung>lmax)
- {
- lmax=lung;
- }
- i=j;
- }
- i++;
- }
- cout<<lmax;
- }
- else if(p == 2)
- {
- int cont = 0;
- char varf, ant, ch;
- stack<char>steeva;
- ant = s[0];
- steeva.push(ant);
- varf = s[1];
- steeva.push(varf);
- int pas = 2;
- while(pas<=n)
- {
- ch = s[pas];
- if(ant>varf && varf<ch)
- {
- cont+=max(ant-'a'+1, ch-'a'+1);
- cout<<max(ant-'a'+1, ch-'a'+1)<<"#"<<varf<<endl;
- steeva.pop();
- steeva.push(ch);
- varf = ch;
- }
- else{
- ant = varf;
- varf = ch;
- steeva.push(ch);
- pas++;
- }
- }
- cout<<cont;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement