Description
一天,wm和zyf想比比谁比较正气,但正气这种东西无法量化难以比较,为此,他们想出了一个方法,两人各写一个数字,然后转化为二进制,谁的数字中二进制1多谁就比较正气!
Input
输入包含多组数据,EOF结束。
每组数据包含两行,代表两个非负整数a,b(0<=a,b<10^100,不含前导0),a为wm写的数字,b为zyf写的数字。
每组数据包含两行,代表两个非负整数a,b(0<=a,b<10^100,不含前导0),a为wm写的数字,b为zyf写的数字。
Output
每组数据输出一行,输出正气的西电人名字"wm"或"zyf",如果两人的数字中二进制1一样多就输出"neither"。
Sample Input
15
16
17
18
20
19
16
17
18
20
19
Sample Output
wm
neither
zyf
neither
zyf
题目分析:
由于a,b是非常大的长整数,因此需要长整数算法,对于一个整数来说,求其二进制中1的个数就是 模2,然后再除2,直到这个数变为0 ,看看模2的过程中出现了几次1。那么对于长整数也是这样的,因为长度范围是100位,如果我们用一个数组,每个数组项标示5位,这样可以减少进位的计算。具体代码如下
1 #include <iostream> 2 #include <string.h> 3 #include <stdlib.h> 4 using namespace std; 5 6 7 int com(char * str) 8 { 9 int res = 0 ; 10 int i , j , k , l ; 11 l = 0 ; 12 unsigned int tmp[30]; 13 for(i = strlen(str); i > 0 ; i -= 5){ 14 j = i - 5; 15 k = j > 0 ? j:0 ; 16 const char * nump = (str+k); 17 tmp[l++] = atoi(nump); 18 str[k] = '