您的位置:首页 > 产品设计 > UI/UE

SGU 506 Subsequences Of Substrings

2013-11-23 20:08 309 查看
这个题 还是比较简单的; 把案例 想出来是怎么来的;差不多就出来了; 只要从前往后扫,遇到一个子序列就统计一次,更新起点;

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

char str[112345],cha[112];
int main( )
{
while( scanf("%s%s",str+1,cha+1) != EOF )
{
int len1 = strlen(str+1); int len2 = strlen(cha+1);
int pre = 0; int now = 0; int k = 1; long long res = 0; int i = 1;
while( i <= len1 )
{
if( str[i] == cha[k] )
{
if( k == 1 )now = i;
if( k == len2 )
{
res += (long long)(now-pre)*(long long)(len1-i+1);
k = 1; pre = now; i = now+1; now = 0;
}else { i++; k++; }
}else i++;
}
printf("%lld\n",res);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: