user-0 提问: 请教一下各位大神，图中的这道题目应该怎么做？

回复:
user: user-1
content: # include <stdio.h> # define N 20 void change(int *a,int *b){//交换函数         int c=*a;         *a=*b;         *b=c;     }     void paixu(int A[][N],int left,int right)//快速排序升序     {         int i=left,j=right,temp[2]={A[0][left],A[1][left]};         if(left>=right)  return;         while(i!=j)         {             while((A[0][j]<temp[0]||A[0][j]==temp[0]&&A[1][j]>=temp[1])&& i<j)j--;             while((A[0][i]>temp[0]||A[0][i]==temp[0]&&A[1][i]<=temp[1])&& i<j)i++;             if(i<j)             {                 change(&A[0][i],&A[0][j]);                 change(&A[1][i],&A[1][j]);             }     }     if(i!=left)     {         change(&A[0][left],&A[0][i]);         change(&A[1][left],&A[1][i]);     }         paixu(A,left,i-1);         paixu(A,i+1,right);     }   int main(){ 	char A[N]={"\0"}; 	int S[2][N]; 	int B,C,i; 	freopen("A.txt","r",stdin); 	scanf("%d",&B); 	while(B--){ 	 scanf("%d",&C); 	 i=0; 	 while(C){ 	 	A[i++]+=C&1; 	 	C=(C>>1); 	 }	 	} 	for(i=0;i<N;i++) 	{ 		S[1][i]=1<<i; 		S[0][i]=A[i]; 	} 	paixu(S,0,N-1); 	for(i=0;i<N;i++) 	  if(S[0][i]) 	  printf("%d %d\n",S[1][i],S[0][i]); 	return 0; }  解决了能给我分数吧？

user: user-1
content: # include <stdio.h> # define N 20 int main(){ 	char A[N]={"\0"},D[N]={"\0"}; 	int B,C,i; 	freopen("A.txt","r",stdin); 	scanf("%d",&B); 	while(B--){ 	 scanf("%d",&C); 	 i=0; 	 while(C){ 	 	A[i++]+=C&1; 	 	C=(C>>1); 	 }	 	} 	for(i=0;i<N;i++) 	if(A[i]) 	  printf("%d %d\n",1<<i,A[i]); 	return 0; }  剩下的你自己排个序即可

user: user-1
content: //11的二进制代码为1011 所以投票就是 //把一个整数转化为二进制 然后把带有1的个数给合计出来即可 //用位运算 # include <stdio.h> int main(){     int A=11,num=0;    while(A) {    num+=A>>1;   A=A>>1;    } printf("%d",num);     return 0; }

user: user-2
content: int num = 6;             int[] arrvote = { 1, 3, 7, 1023, 2048, 128 };             int[] tech = new int[20];             for (int i = 0; i < num; i++)             {                 for (int j = 0; j <20; j++)                 {                     if ((arrvote[i] >> j & 0x01) != 0)                         tech[j]++;                 }             }

user: user-2
content: lz，贴的图全吗？ 如果全的话差一张票2048

user: user-3
content: 取前十名，在print_cnt函数里，for循环条件改成MAX_TEACH_NUM/2

user: user-4
content: 有奇数的全部减1并计入1号教师，现在所有投票都是偶数了，分别循环除以2，直到结果为1，排列组合的思想统计票数。题目中缺少是否可以一个学生可以给一个老师投多张票或者是只投给一个老师的信息

user: user-3
content: #include <stdio.h> #include <stdlib.h>  struct teacher {     int id;     int cnt; };  #define     MAX_TEACH_NUM   20  static void init_id(struct teacher *pteach, int num); static void print_cnt(struct teacher *pteach, int num); void bubble_sort(struct teacher *pteach, int num); void count_tickets(struct teacher *pteach, int t_num, unsigned int *tickets, int ticket_num);  int main(void) {     struct teacher teach[MAX_TEACH_NUM];     int *tickets = NULL, num;     int i;       scanf("%d", &num);     tickets = (int *)malloc(sizeof(int) * num);     if (!tickets) {         fprintf(stderr, "malloc error!\n");         exit(-1);     }      for (i = 0; i < num; i++)         scanf("%d", tickets + i);      init_id(teach, MAX_TEACH_NUM);     count_tickets(teach, MAX_TEACH_NUM, tickets, num);     printf("Before sort: \n");     print_cnt(teach, MAX_TEACH_NUM);     bubble_sort(teach, MAX_TEACH_NUM);     printf("After sort: \n");     print_cnt(teach, MAX_TEACH_NUM);       return 0; }  void init_id(struct teacher *pteach, int num) {     int i;      for (i = 0; i < num; i++) {         pteach[i].id = (1u << i);         pteach[i].cnt = 0;     } }  static void print_cnt(struct teacher *pteach, int num) {     int i;      for (i = 0; i < num; i++) {         if (pteach[i].cnt > 0)         printf("ID: %6d\t %d \n", pteach[i].id, pteach[i].cnt);     }  }   void count_tickets(struct teacher *pteach, int t_num, unsigned int *tickets, int ticket_num) {     int i, j;     unsigned int num;      for (i = 0; i < ticket_num; i++) {         num = tickets[i];         for (j = 0; j < t_num; j++) {             if (num & (1u << j))                 pteach[j].cnt++;         }     } }  void bubble_sort(struct teacher *pteach, int num) {     struct teacher tmp;     int i, j;      for (i = 0; i < num -1; i++)         for (j = 0; j < num - 1 - i; j++)             if (pteach[j].cnt < pteach[j+1].cnt) {                 tmp = pteach[j];                 pteach[j] = pteach[j+1];                 pteach[j+1] = tmp;             } } 参考一下，主要是找到ID和投票值之间的关系。 使用的都是基本的C语言知识，如果一点也写不出来，这要问问自己了。

user: user-5
content: 最笨的办法 穷举。投的号码跟每一个老师的号码比较。大于老师的号码就+1

user: user-2
content: 提示  位运算