社区讨论

有哪个大神帮我康康我的代码有什么问题

P3817小A的糖果参与者 4已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@mhjkrwqn
此快照首次捕获于
2025/11/04 04:11
4 个月前
此快照最后确认于
2025/11/04 04:11
4 个月前
查看原帖
CPP
#include<iostream>
#include<vector>

using namespace std;

int main()
{
	int n = 0, x = 0, sum = 0;
	cin >> n >> x;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int temp;
	for (int i = 0; i < a.size(); i++)
	{
		temp = a[i] + a[i + 1];
		if (temp > x)
			sum += temp - x;
	}
	cout << sum << endl;
	return 0;
}

运行后输入完数据之后的弹窗内容是个什么意思
Microsoft Visual C++ Runtime Library

Debug Assertion Failed!

Program: D:\Visual Studio\A\C++F0d0D\x64\Debug\A\Day01.exe
File: D:\VSVC\Tools\MSVC\14.44.35207\include\vector
Line: 1931

Expression: vector subscript out of range

For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)

回复

3 条回复,欢迎继续交流。

正在加载回复...