| Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|
| 129153 | 李朋秦 | 两个数的最小距离 | C++ | Wrong Answer | 2 MS | 276 KB | 760 | 2025-08-22 14:17:02 |
#include <iostream> #include <vector> #include <algorithm> #include <climits> // 用于INT_MAX using namespace std; int main() { int n; cin >> n; // 读取数组长度 vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; // 读取数组元素 } sort(a.begin(), a.end()); // 对数组进行排序 int min_distance = INT_MAX; // 初始化最小距离为最大整数 for (int i = 0; i < n - 1; ++i) { int distance = a[i + 1] - a[i]; // 计算相邻元素的差值 if (distance < min_distance) { min_distance = distance; // 更新最小距离 } } cout << min_distance << endl; // 输出结果 return 0; }
------Input------
2 -2147483648 2147483647
------Answer-----
4294967295
------Your output-----
-1