題目
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;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/75530.html
標籤:C++
上一篇:float和double的區別
