首页 > 其他分享 >HUST 1602 Substring

HUST 1602 Substring

时间:2022-11-09 18:37:50浏览次数:41  
标签:10 there int 1602 HUST Substring printf test include


Description



This problem is quiet easy. 
Initially, there is a string A. 
  
Then we do the following process infinity times. 
 A := A +   “HUSTACM” + A 
  
For example, if a = “X”, then 
After 1 step, A will become   “XHUSTACMX”
After 2 steps, A will become   “XHUSTACMXHUSTACMXHUSTACMX”
  
Let A = “X”, Now I want to know the characters from L to R of the final string.


Input



Multiple test cases, in each test case, there are only one line containing two numbers L and R. 
1 <= L <= R <= 10^12 
R-L <= 100


Output



For each test case, you should output exactly one line which containing the   substring.


Sample Input



5 10


Sample Output



TACMXH

其实生成的串本身就是无限循环的,循环节就是8,所以直接算出L对应的位置就好了。

#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=1e5+10;
LL l,r;
char s[10]={"XHUSTACM"};

int main()
{
while (~scanf("%lld%lld",&l,&r))
{
int len=r-l+1;
for (int i=0;i<len;i++)
{
printf("%c",s[(i+(l-1)%8)%8]);
}
printf("\n");
}
return 0;
}



标签:10,there,int,1602,HUST,Substring,printf,test,include
From: https://blog.51cto.com/u_15870896/5837715

相关文章

  • SPOJ 705 New Distinct Substrings
    DescriptionGivenastring,weneedtofindthetotalnumberofitsdistinctsubstrings.InputT-numberoftestcases.T<=20;Eachtestcaseconsistsofonestr......
  • HUST 1599 Multiple
    DescriptionRocket323 lovesmathverymuch.Oneday, Rocket323 gotanumberstring.Hecouldchoosesomeconsecutivedigitsfromthestringtoform......
  • HUST 1600 Lucky Numbers
    DescriptionIsun lovesdigit4and8verymuch.Hethinksanumberisluckyonlyifthenumbersatisfythefollowingconditions: 1.      The......
  • HDU 1403 Longest Common Substring
    ProblemDescriptionGiventwostrings,youhavetotellthelengthoftheLongestCommonSubstringofthem.Forexample:str1=bananastr2=ciana......
  • Substring 在BCL和CLR里面搞了啥
    楔子还是做点事情,不要那么散漫。本文以简单的Substring(intstartindex,intLength)函数为例,来递进下它在托管和非托管的一些行为。以下均为个人理解,如有疏漏请指正。......
  • [LeetCode] 1668. Maximum Repeating Substring
    Forastring sequence,astring word is k-repeating if word concatenated k timesisasubstringof sequence.The word's maximum k-repeatingvalue......
  • [数据库基础]-- 字符串截取函数substr、substring以及 case when函数使用
    使用说明:1、使用:substr使用范围:oracle、mysql、sqlserversubstring使用范围:mysql、sqlserver 2、举例:现有表:t_user name、age字段查询需求:如果name字段中的第5个字符有“......
  • CF1729G Cut Substrings 题解
    CF1729GCutSubstrings给出两个字符串\(s,t\),每次可以将字符串\(s\)中任意一个为\(t\)的子串删除,删除位置的字符变为空格(或理解为无实义)。求最少删除几次可以使得......
  • 1602:烽火传递
    序列A,选择一些a[i],任意一个长度为m的区间内至少有一个所选的问sum{a[i]}的最小值 #include<iostream>#include<cstring>usingnamespacestd;constint......
  • 【ABC196F】Substring 2(多项式乘法)
    我竟然能在AT当场做出F题!哦,是ABC啊,没事了。以下的字符串均从\(1\)开始记位。以下设\(S_i\)表示字符串\(S\)的第\(i\)位,\(S(l,r)\)表示字符串\(S\)的第......