-
Notifications
You must be signed in to change notification settings - Fork 0
/
squeeze.cc
31 lines (27 loc) · 922 Bytes
/
squeeze.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <list>
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <time.h>
#include <stdlib.h>
#define basemax 50
#define sizek 25
// code cut <input >output
// explores the numberss in the input file
// if they are longer than cut, they are transformed in s1(d^n)s2
// the result is sent to the output file
using namespace std;
using sint=long unsigned int; // std::vector<std::__cxx11::basic_string<char> >::size_type;
ifstream lresu;
int main(int argc, char *argv[])
{string p,exp,ms,prefms,s1,s2; long int i,j,k,l; sint cut; char ss;
cut=atoi(argv[1]);
while(cin>>p)
{if(p.length()<=cut){cout<<p<<"\n";continue;}
k=cut/2;ss=p[k];l=1;
for(i=k-1;i>=0;i--)if(p[i]!=ss)break;else l++;
for(j=k+1;j<p.length();j++)if(p[j]!=ss)break;else l++;
cout<<p.substr(0,i+1)<<"("<<ss<<"^"<<l<<")"<<p.substr(j,p.length())<<"\n";
}
} // end main