Huawei trial-name of husband and wife, Huawei name of husband and wife
Question: Husband and Wife
In China, most people use the word "Husband and Wife ". The so-called "Husband and Wife" means that two people seem to be perfect, and there are some similarity in appearance, body, and other aspects.
This question is another way to find the most "Husband and Wife" from the perspective of human name and the number of repeated letters.
The name of a group of ladies is prefixed in the question. Enter the name of the man in pinyin (there can be spaces in the middle of the pinyin text, and all the letters are in lower case), traverse all the names according to the preconfigured name in pinyin, and output the name of the lady with the most repeated letters.
Rule 1: If multiple women with the most repeated letters are the same, the first matched lady will be the most "Husband and Wife" candidate.
Rule 2: the same letters in a person's name are processed once. For example, the number of repeated characters between li ling and li lei is 2, not 4.
Preset ladies list (must be ensured in sequence ):
"Wang fei ",
"Zhang man yu ",
"Zhang zhi yi ",
"Li ",
"Li xiao man ",
"Li yu cun ",
"Yang ni ",
"Xiao tong ",
"Li lei ",
"Zhang san"
Running time limit: Unlimited
Memory limit: Unlimited
Input: enter a man's name, string
Output: name of the lady with the most "Husband and Wife"
Basic Ideas:
Find the letters in the men's and women's names, such as wang yun. The letters are a, g, n, y, u, w. then match the number of duplicate letters in the two names. If both of them contain a letter, add 1 to the number of duplicates.
#include<stdio.h>#include<string.h>char nameArray[10][26]={"wang fei","zhang man yu","zhang zhi yi","li li","li xiao man","li yu cun","yang ni","xiao tong","li lei","zhang san"};char male[100];bool female_cnt[10][26];bool male_cnt[26];void init(){ for(int i=0;i<10;++i) { for(int j=0;j<strlen(nameArray[i]);++j) { if(nameArray[i][j]!=' ') female_cnt[i][nameArray[i][j]-'a']=1; } }}int main(int argc, char *argv[]){ init(); gets(male); for(int i=0;i<strlen(male);++i) if(male[i]!=' ') male_cnt[male[i]-'a']=1; int max_index=0; int max_count=0; for(int i=0;i<10;++i) { int count=0; for(int j=0;j<26;++j) { if(male_cnt[j]&&female_cnt[i][j]) count++; } if(count>max_count) { max_index=i; max_count=count; } } printf("%s\n",nameArray[max_index]); return 0;}