思路:只能用异或,平常数组或者hashmap存储会超时,而且java一直超时……可能读入流太慢了,然后换的c才AC不过思路是一样的,下面是Python测试异或上偶数个相同的数之后结果是不是原来的结果
下面上C代码:
int main() { int n,x,m; while(~scanf("%d",&n),n) { x=0; while(n--) { scanf("%d",&m); x^=m; } printf("%d ",x); } return 0; }
下面是java代码:
package hduoj; import java.util.Scanner; public class hdoj_2095 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(true){ int count = sc.nextInt(); if(count == 0) break; int res = 0; while(count-- != 0){ int temp = sc.nextInt(); res ^= temp; } System.out.println(res); } } }
代码已经ac
希望对大家有所帮助
以上