您的位置:首页 > 其它

1093. Count PAT's

2015-03-22 10:14 183 查看
#include<cmath>

#include<cstdio>

#include<cstring>

#include<iostream>

#include<vector>

/*#include<unordered_set>*/

#include<list>

#include<algorithm>

#include<ctime>

using namespace std;

#define LOCAL

struct node{

int index;

int len;

};

vector<node >p;

vector<node >a;

vector<node >t;

void findchar(string s,int len)

{

/* vector<node >v;*/

/* if(c=='P')*/

/* v=&p;*/

/* if(c=='A')*/

/* v=&a;*/

/* if(c=='T')*/

/* v=&t;*/

int i,j;

for(i=0;i<len;++i)

{

if(s[i]=='P')

{

node tmp;

tmp.index=i;

for(j=i;j<len;++j)

{

if(s[j]!='P')

break;

}

tmp.len=j-i;

i=j-1;

p.push_back(tmp);

}else if(s[i]=='A')

{

node tmp;

tmp.index=i;

for(j=i;j<len;++j)

{

if(s[j]!='A')

break;

}

tmp.len=j-i;

i=j-1;

a.push_back(tmp);

}else if(s[i]=='T')

{

node tmp;

tmp.index=i;

for(j=i;j<len;++j)

{

if(s[j]!='T')

break;

}

tmp.len=j-i;

i=j-1;

t.push_back(tmp);

}

}

}

int main()

{

/* clock_t start=clock();*/

#ifdef LOCAL

freopen("testin.data","r",stdin);

freopen("testout.data","w",stdout);

#endif

int n,m;

int i,j,k;

char s[100001];

gets(s);

string st0,st1;

st0=s;

i=st0.find('P');

if(i>=strlen(s))

{

printf("0\n");

return 0;

}

st0=st0.substr(i,st0.size()-i);

reverse(st0.begin(),st0.end());

i=st0.find('T');

if(i>=st0.size())

{

printf("0\n");

return 0;

}

st0=st0.substr(i,st0.size()-i);

reverse(st0.begin(),st0.end());

printf("%s\n",st0.c_str());

int leng=st0.size();

findchar(st0,leng);

/* findchar(st0,leng,'A',a);*/

/* findchar(st0,leng,'T',t);*/

int len0=p.size(),len1=a.size(),len2=t.size();

if(len0<1 || len1<1 || len2<1)

{

printf("0");

return 0;

}

long sum=0;

for(i=0;i<len0;++i)

{

for(j=0;j<len1;++j)

{

if(p[i].index>=a[j].index)

continue;

for(k=0;k<len2;++k)

{

if(a[j].index>=t[k].index)

continue;

/* if(p[i].index<a[j].index && a[j].index <t[k].index)*/

else

{

sum+=p[i].len*a[j].len*t[k].len;

}

}

}

}

sum%=1000000007;

printf("%ld\n",sum);

/* clock_t end=clock();*/

/* printf("%.41lf Mseconds\n",((double)(end-start)/CLOCKS_PER_SEC)*1000);*/

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: