1158: 取字符串
Submit Page Summary Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 1010 Solved: 345Description
有个长度为1000000以内的字符串C,提供整数a,b,d,e,计算ans=a*b%d,然后取C从第e(e的取值从0开始)号位置的字符开始长度为ans的那子串并输出。(1<=a,b<=5000)数据保证子串不超过C的字符串范围。
Input
有多组测试数据,对于每组数据,第一行为4个整数,a,b,d,e,第二行为给定的字符串C。
Output
对于每组测试数据,输出所求的子字符串。
Sample Input
3 4 5 1 abcdefghijk
Sample Output
bc
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=1e6+10;
char s[maxn];
int main()
{
int a,b,d,e,ans;
while(std::cin>>a>>b>>d>>e)
{
cin>>s;
ans=a*b%d;
for(int i=e;i<e+ans;i++)
cout<<s[i];
cout<<endl;
}
return 0;
}