#include<stdio.h>
#include<iostream>
#include<string.h>
char findTheDifference(char* s, char* t) {
int i, j,s1=0,s2=0;
for (i = 0; i < strlen(s)+1; i++)
{
s1 += s[i];
s2 += t[i];
}
return(char)(s2 - s1);
}
int main()
{
char *s = (char*)malloc(sizeof(char) * 100);
char *t = (char*)malloc(sizeof(char) * 100);
scanf("%s", s);
//scanf("%s", t);随机产生
char k;
k = findTheDifference(s, t);
printf("%c", k);
system("pause");
return 0;
}
方法二:
char findTheDifference(char* s, char* t) {
char ss=0;
int i, j;
for (i = 0; i < strlen(s); i++)
{
ss ^= s[i];
}
for (i = 0; i < strlen(s) + 1; i++)
{
ss ^= t[i];
}
return ss;
}
single number(只有一个出现奇数次)
nt singleNumber(int a[], int n) {
int num = 0;
for (int i = 0; i < n; ++i) {
num ^= a[i];
}
return num;
}