版本比较
CSP-J 大纲
正文
增加 15 行删除 15 行
188 行未改动全部展开18919019119219319319419519619719719819920020120220220320420520612 行未改动21922022122222322322422522622722822922923023123223323423523623723723823924024122 行未改动26426526626726826826927027127227327427527627727727827928028120 行未改动30230330430530630630730830931059 行未改动37037137237337437437537637737850 行未改动42943043143243343343443543643748 行未改动486487488489490490491492493494495496496497498499500127 行未改动全部展开62862963063163263263363463563687 行未改动7247257267277287287297307317324 行未改动188 行未改动全部展开 long long b = 1e18; double c = 3.14159; char d = 'A'; bool e = true;
// 算术运算符 int sum = a + 5; int mod = a % 3; // 10 % 3 = 1
// 位运算符 int bit_and = a & 3; // 1010 & 0011 = 0010 (2) int bit_or = a | 3; // 1010 | 0011 = 1011 (11) int left_shift = a << 1; // 1010 << 1 = 10100 (20)
cout << "sum: " << sum << ", mod: " << mod << endl; return 0;}```12 行未改动 cout << "Negative" << endl; } else { cout << "Zero" << endl; }
// for循环 for (int i = 0; i < 5; i++) { cout << i << " "; } cout << endl;
// while循环 int j = 0; while (j < 5) { cout << j << " "; j++; } cout << endl;
// switch-case int day = 3; switch (day) { case 1: cout << "Monday"; break;22 行未改动int main() { // 一维数组 int nums[5] = {1, 2, 3, 4, 5}; cout << "Sum: " << arraySum(nums, 5) << endl;
// 二维数组 int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}}; for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { cout << matrix[i][j] << " "; } cout << endl; }
// 字符串操作 string s = "Hello"; s += " World"; cout << s << ", length: " << s.length() << endl;20 行未改动 int *p = &x; // 指针指向x的地址 cout << "x = " << x << ", *p = " << *p << endl; *p = 20; // 通过指针修改x的值 cout << "x = " << x << endl;
// 引用示例 int a = 5, b = 10; swap(a, b); cout << "a = " << a << ", b = " << b << endl; // 输出10,559 行未改动 cout << st.top() << " "; // 3 2 1 st.pop(); } cout << endl;
// 队列(FIFO) queue<int> q; q.push(1); q.push(2);50 行未改动 root->left = new TreeNode(2); root->right = new TreeNode(3); root->left->left = new TreeNode(4); root->left->right = new TreeNode(5);
cout << "Preorder: "; preorder(root); cout << endl; // 1 2 4 5 3 cout << "Inorder: "; inorder(root); cout << endl; // 4 2 5 1 3 cout << "Postorder: "; postorder(root); cout << endl;// 4 5 2 3 1 return 0;48 行未改动 adj[0].push_back(2); adj[1].push_back(3); adj[1].push_back(4); adj[2].push_back(4);
// DFS visited.assign(n, false); cout << "DFS: "; dfs(0); // 0 1 3 4 2 cout << endl;
// BFS visited.assign(n, false); cout << "BFS: "; bfs(0); // 0 1 2 3 4127 行未改动全部展开
int main() { vector<int> a = {1, 2, 3, 4, 5}; cout << "区间[2,4]的和:" << prefixSum(a, 2, 4) << endl; // 2+3+4=9
rangeAdd(a, 2, 4, 10); // 区间[2,4]各元素加10 for (int x : a) { cout << x << " "; // 1 12 13 14 5 }87 行未改动 vector<int> a, b; // 字符串转逆序数字数组 for (int i = sa.size()-1; i >= 0; i--) a.push_back(sa[i] - '0'); for (int i = sb.size()-1; i >= 0; i--) b.push_back(sb[i] - '0');
vector<int> c = add(a, b); reverse(c.begin(), c.end()); // 逆序后输出 for (int x : c) { cout << x; // 123456 + 7890 = 1313464 行未改动