A - New Year and Naming

The meaning of problems: two input sequences Sn and Tm, sequence comprising n / m space-separated substrings, enter the year year, from cyclically and successively extracted two sequences a sequence, consisting of characters may represent a year string, this question is similar attribution chronology.

Thinking: Year of the magic sequence number per piece, two ends of the string that represents the year, i.e. the composition.

It will not explain the problem, details could not speak, the focus catch.

#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

Guess you like

Origin www.cnblogs.com/DreamingBetter/p/12181041.html