前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HUST 1602 - Substring

HUST 1602 - Substring

作者头像
ShenduCC
发布2018-04-26 11:52:44
7680
发布2018-04-26 11:52:44
举报
文章被收录于专栏:算法修养

题目描述 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. 输入 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 输出 For each test case, you should output exactly one line which containing the substring. 样例输入 5 10 样例输出 TACMXH

代码语言:javascript
复制
#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>

using namespace std;
long long int l,r;
char a[9];
int main()
{
    a[0]='H';
    a[1]='U';
    a[2]='S';
    a[3]='T';
    a[4]='A';
    a[5]='C';
    a[6]='M';
    a[7]='X';
    while(scanf("%lld%lld",&l,&r)!=EOF)
    {
        int pos;
        if(l==1)
            pos=7;
        else
            pos=(l-2)%8;
         int cnt=1;
         while(cnt<=(r-l)+1)
         {
             printf("%c",a[(pos)%8]);
             pos++;
             cnt++;
         }
         printf("\n");


    }
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-03-09 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档