-
Notifications
You must be signed in to change notification settings - Fork 0
/
xpand.cc
30 lines (26 loc) · 938 Bytes
/
xpand.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
#include <list>
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <time.h>
#include <stdlib.h>
#define basemax 50
#define sizek 25
// code <input >output
// expands in the classical form s1dddd...dddds2 on the output file
// the numberss given in the form s1(d^n)s2 in the input 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;
while(cin>>p)
{s1="";for(i=0;i<p.length();i++)if(p[i]=='(')break;else s1+=p[i];
if(i==p.length()){cout<<p<<"\n";continue;}ss=p[++i];i++;exp="";
for(j=i+1;j<p.length();j++)if(p[j]==')')break;else exp+=p[j];
s2="";for(k=j+1;k<p.length();k++)s2+=p[k]; l=stoi(exp);
ms="";for(i=0;i<l;i++)ms+=ss;
cout<<s1<<ms<<s2<<"\n";
}
} // end main