online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, COBOL, HTML, CSS, JS Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ #include<iostream> // 引入标准输入输出库 using namespace std; int a[100]; // 定义数组 a,长度为 100 int b[100]; // 定义数组 b,长度为 100 int now; // 定义变量 now,用于存储查询时的临时最大值 int main() { int n; // 定义变量 n,用于存储输入的元素个数 cin >> n; // 输入元素个数 n // 输入数组 a 的元素 for (int i = 0; i < n; i++) { cin >> a[i]; } // 遍历数组 a 的每一个元素,计算数组 b 的对应值 for (int i = 0; i < n; i++) { now = a[i-1]; // 初始化 now 为 a[i-1], // 如果是第一个或最后一个元素,b[i] 初始化为 1,否则为 2 if (i == 0 || i == n-1) b[i] = 1; else b[i] = 2; // 检查当前元素之前的元素,统计比当前元素大的元素个数 for (int j = i-2; j >= 0; j--) { if (a[j] > now) { // 如果 a[j] 比当前最大值 now 大 now = a[j]; // 更新当前最大值 b[i]++; // 增加计数 } } now = a[i+1]; // 初始化 now 为 a[i+1],但在 i = n-1 时会读取到无效值 // 检查当前元素之后的元素,统计比当前元素大的元素个数 for (int j = i+2; j < n; j++) { if (a[j] > now) { // 如果 a[j] 比当前最大值 now 大 now = a[j]; // 更新当前最大值 b[i]++; // 增加计数 } } } // 输出数组 b 的所有元素 for (int i = 0; i < n; i++) { cout << b[i] << " "; } return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue