SETNJA - Setnja
Tác giả: hieult
Ngôn ngữ: C++
//#include <conio.h>
#include <stdio.h>
#include <string.h>
#define du 100000000
struct so
{
int scs,a[2000];
};
so gt,sl;
char s[10001];
void print(so A)
{
int n = A.scs;
printf("%d",A.a[n]);
for(int i = n-1;i>=1;i--)
printf("%08d",A.a[i]);
}
/* Tinh Tong */
void sum(so &tong, so b)
{
so A = tong;
if(A.scs > b.scs) for(int i = b.scs+1; i <= A.scs; i++) b.a[i] = 0;
if(b.scs > A.scs) {for(int i = A.scs+1; i <= b.scs; i++) A.a[i] = 0; tong.scs = b.scs;}
int nho = 0;
for(int i = 1; i <= tong.scs ; i++)
{
tong.a[i] = (A.a[i] + b.a[i] + nho)%du;
nho = (A.a[i] + b.a[i] + nho)/du;
//printf("%c ",a[i]);
}
if(nho > 0){ tong.scs++ ; tong.a[tong.scs] = nho ;}
}
void tich(so &f,int k)
{
int nho = 0,t;
for(int j = 1;j<=f.scs;j++)
{
t = f.a[j];
f.a[j] = (t*k+nho)%du;
nho = (t*k+nho)/du;
}
if(nho>0) f.a[++f.scs] = nho;
}
int main()
{
FILE* f;
//f = fopen("SETNJA.in","wt");
// for(int i = 1;i<=10000;i++)
//fprintf(f,"*");
//fclose(f);
//freopen("SETNJA.in","r",stdin);
scanf("%s",s);
gt.scs = 1; gt.a[1] = 1;
sl.scs = 1; sl.a[1] = 1;
//printf("%d\n",strlen(s));
for(int i = 0;i<strlen(s);i++)
{
if(s[i] == 'L')
sum(gt,gt);
else if(s[i]=='R')
{
sum(gt,gt);
sum(gt,sl);
}
else if(s[i]=='*')
{
tich(gt,5);
sum(gt,sl);
tich(sl,3);
}
}
print(gt);
//getch();
}