C++ learning vector articles

1. Enter a line of numbers or strings (unknown number), spaced by spaces, end the input and output after a new line

	// 数字
	unsigned int buf, index = 0;
	vector<unsigned int> arr(1000000);
	while (cin >> buf)
	{
    
    
		arr[index++] = buf;
		char ch = getchar(); // 通过getchar()来判断最后输入回车符结束 
		if (ch == '\n')
			break;
	}
	// 字符串
	string str;
	getchar(cin, str);

Refer to C++ to input a line of numbers or strings (unknown number), spaced with spaces, end the input and output after a newline

2. Initialize the vector

	vector<unsigned int> arr(1000000, 0); // 初始化了 一百万 个值为0的vector数组;

Reference C++: Summary of initialization definition and assignment method of vector

3. Remove duplicate numbers

Refer to the super simple C++ deduplication and sorting

Guess you like

Origin blog.csdn.net/weixin_45827203/article/details/129653257