zoukankan      html  css  js  c++  java
  • Who will be punished

    Who will be punished 

    Problem Description

    This time,suddenly,teacher Li wants to find out who have missed interesting DP lesson to have fun.The students who are found out will get strictly punishment.Because,teacher Li wants all the students master the DP algorithm.
    However,Li doesn't want to waste the class time to call over the names of students.So he let the students to write down their names in one paper.To his satisfaction,this time, only one student has not come.
    He can get the name who has not come to class,but,it is troublesome,and,teacher always have many things to think about,so,teacher Li wants you, who is in the ACM team, to pick out the name.

    Input

    The first line of each case have one positive integer N.N is the number of the students,and N will not greater than 500,000.
    Then,following N lines,each line contains one name of students who have attended class.The N-1 lines are presented after N lines.These N-1 lines indicates the names of students who have come to class this time,one name in one line.
    The length of student's name is not greater than 30.

    Output

    output the name of the student who have not come to class.

    Sample Input

    3
    A
    B
    C
    B
    C
    

    Sample Output

    A

    解释:

    找到只出现过一次的人的名字,而其他人都出现了两次。那么用一个字符串去异或,异或。毕竟东一个名字的,出现两次,那么两次的相同位置的字符肯定是一样。

     1 #include<stdio.h>
     2 #include<string.h>
     3 int main()
     4 {
     5 void fun(int n);
     6     int n;
     7     while(scanf("%d",&n)!=EOF)
     8     fun (n);
     9     return 0;
    10 }
    11 void fun (int n)
    12 {  int j,i,a;
    13  char str1[31],str2[31];
    14    n=n*2;
    15         for(i=0;i<31;i++)
    16             str2[i]=0;        
    17         for(i=0;i<n;i++)
    18         {
    19             gets(str1);
    20             a=strlen(str1);
    21             for(j=0;j<a;j++)
    22             str2[j]=str1[j]^str2[j];
    23         }
    24         puts(str2);    
    25 }
    View Code
  • 相关阅读:
    PHP中无限分类、无限回复评论盖楼的实现方法,thinkphp5.0无限分类实例
    PHP中session详解
    使用thinkPHP做注册程序的实例
    虾米盒子系统开发APP
    angular 使用base64密码加密
    开发中遇到的两种表格文本长度处理,即长文本截断
    树组件使用文件夹图标
    angular实现指定DIV全屏
    JS调用浏览器打印机
    使用blob二进制流的方式下载后台文件
  • 原文地址:https://www.cnblogs.com/gznb/p/11213688.html
Copyright © 2011-2022 走看看