Find only appears once in the array of digital / contents of the array of characters as: "student a am i", changed to "i am a student

A set of data in a number appears only once.
All other numbers are in pairs.
Look for this number. (Using bit operation)
[0] XOR solving ideas have any number equal to the number itself. The same number zero XOR

int Seek_num(int arr[],int len)
{
	int ret = 0;
	for (int i = 0; i < len; i++)
	{
		ret = ret^arr[i];
	}
	return ret;
}
int main()
{
	int arr[] = { 2, 2, 3, 4, 5, 7, 3, 5, 4 };
	int len = 0;
	len = sizeof(arr) / sizeof(arr[0]);
	printf("%d\n",Seek_num(arr,len));
	system("pause");
	return 0;
}

There is a character array of content: "student a am i",
please read the contents of the array you "i am a student".
Requirements:
You can not use the library functions.
Only a limited number of open spaces (regardless of the number of space and character string length).
// i ma a tneduts

void Reversed_Num(char* arr)
{
	char* start = arr;
	char* end = arr;
	while (*end != '\0')
	{
		++end;
	}
	--end;
	while (start < end)
	{
		char temp = *start;
		*start = *end;
		*end = temp;
		++start;
		--end;
	}
	
}
void Reversed(char* arr)
{
	while (*arr != '\0')
	{
		char* start = arr;
		char* end = arr;
		while (*end != ' '&&*end != '\0')
		{
			end++;
		}
		--end;
		while (start < end)
		{
			char temp = *start;
			*start = *end;
			*end = temp;
			++start;
			--end;
		}
		while (*arr != ' '&&*arr != '\0')
		{
			++arr;
		}
		if (*arr != '\0')
		{
			++arr;
		}
	}
}
int main()
{
	char arr[] = "student a am i";
	printf("%s\n", arr);
	Reversed_Num(arr);
	printf("%s\n", arr);
	Reversed(arr);
	printf("%s\n", arr);
	system("pause");
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_44936160/article/details/90605812