首页 > 其他 > 详细

【题解】 CF1284A New Year and Naming

时间:2020-01-05 11:45:32      阅读:72      评论:0      收藏:0      [点我收藏+]

题目

CF1284A New Year and Naming

题目大意

给你两个序列,序列 \(1\) 长度为 \(n\),序列 \(2\) 长度为 \(m\)。序列中每一个元素都是字符串。\(q\) 个询问,每次问你序列 \(1\) 和序列 \(2\) 中的第 \(x\) 个元素拼起来是什么。

  • 如果 \(x = n + 1\),就是序列 \(1\) 的第一个元素和序列 \(2\) 的第 \(x\) 个元素拼起来。

思路

答案就是序列 \(1\) 的第 \(x \% n\) 个元素与序列 \(2\) 的第\(x \% m\)个元素拼起来。注意判断 \(x \% n,x \% m\)是否等于零。

\(Code\)

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#define MAXN 21

inline void read(int &T) {
    int x=0;bool f=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    T=f?-x:x;
}

int n,m,q;
std::string s[MAXN],t[MAXN];

int main() {
    read(n),read(m);
    for(int i=1;i<=n;++i) std::cin>>s[i];
    for(int i=1;i<=m;++i) std::cin>>t[i];
    read(q);
    for(int i=1,x;i<=q;++i) {
        read(x);
        int place1=x%n,place2=x%m;
        if(place1==0) place1=n;
        if(place2==0) place2=m;
        std::cout<<s[place1]<<t[place2]<<'\n';
    }
    return 0;
}

【题解】 CF1284A New Year and Naming

原文:https://www.cnblogs.com/poi-bolg-poi/p/12151613.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!