WOJ1340-Easy or Hard

This is the Fifth Problem in this contest. Maybe this is not an easy one, but I think you are clever enough to solve it. Try your best! 

As is known to all, most people's name can be divided into two part, one part is the family name and the other part is the given name. In Chinese we write family name before given name, but in English we write the given name first. Now the task is below: 
Given N names written in Chinese Type, you should change them into English Type. 

输入格式

In the first line, there is an Integer N(1<=N<=1000), which means there are N test cases in the problem.
There are N lines followed, each contains two strings and the total length of them is less than 200. The first one is the family name and the second one is the given name.

输出格式

For each test case, you should output a line contains two strings with a space character between them, the first one is the given name and the second one is the family name. What's more, we all know that the first character of the family name and the given name should be an uppercase one and other characters should be a lowercase one, so if there are mistakes in the strings, you must correct them.

样例输入

3
Zhang Wei
Wang LiangJing
Zhou Chen

样例输出

Wei Zhang
Liangjing Wang
Chen Zhou


#include<stdio.h>
#include<string.h>
int main(){
    int i,t,j,l,n;
    scanf("%d",&t);
    char name[2][200];
    for(i=0;i<t;i++){
    	scanf("%s %s",&name[0],&name[1]);
    	for(j=0;j<2;j++){
    		l=strlen(name[j]);
    		n=0;
    		while(n<l){
    			if((n==0)&&(name[j][0]>='a')&&(name[j][0]<='z'))
    			name[j][0]-=32;
    			else if((n>0)&&(name[j][n]>='A')&&(name[j][n]<='Z'))
				name[j][n]+=32;
				n++;
			}
		}
		printf("%s %s\n",name[1],name[0]);
	}
	return 0;
}


猜你喜欢

转载自blog.csdn.net/lxq1071717521/article/details/77921565
今日推荐