A New Year and Naming

题意:输入两个序列Sn和Tm,序列包含n/m个用空格隔开的子串,输入年份year,循环地从两个序列按顺序分别抽出一个子序列,组成一个可以表示年份的字符串,此题类似天干地支纪年法。

思路:年份魔上每段子序列的个数,两端组成的字符串即表示该年份。

不是很会讲解题目,细节讲不出,重点抓不到。

#include<stdio.h>
#include<string.h>
int main(){
        int n,m,q,y,i,j,year,a,b,k;
        char s[50][50],t[50][50],s1[1100],t1[1100];
        char *temp1,*temp2;
        while(~scanf("%d %d\n",&n,&m)){
                gets(s1);
                temp1=strtok(s1," ");
                i=1;
                while(temp1){
                        strcpy(s[i],temp1);
                        temp1=strtok(NULL," ");
                        i++;
                }
                strcpy(s[0],s[--i]);
                gets(t1);
                temp2=strtok(t1," ");
                i=1;
                while(temp2){
                        strcpy(t[i],temp2);
                        temp2=strtok(NULL," ");
                        i++;
                }
                strcpy(t[0],t[--i]);
                scanf("%d",&q);
                while(q--){
                        scanf("%d",&year);
                        a=year%n;
                        b=year%m;
                        printf("%s%s",s[a],t[b]);
                        printf("\n");
                }
        }
}
View Code
原文地址:https://www.cnblogs.com/DreamingBetter/p/12181041.html