四大文化赛道完整展开
03-execution/run-002/source-snapshot/main.cpp
main.cpp
站内文件视图直接读取仓库内容,Markdown 使用文档排版渲染,其余文本文件保持原始排版,方便校对训练证据链。
文件类型.cpp
10-cases/s3-jh-07-ledger-audit/03-execution/run-002/source-snapshot/main.cpp
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
if (!(cin >> n)) {
return 0;
}
map<string, long long> stock;
long long turnover = 0;
int first_error = 0;
for (int line_no = 1; line_no <= n; ++line_no) {
string name, op;
long long qty, price;
cin >> name >> op >> qty >> price;
long long current = stock[name];
if (op == "IN") {
stock[name] = current + qty;
continue;
}
if (qty > current) {
if (first_error == 0) {
first_error = line_no;
}
continue;
}
stock[name] = current - qty;
turnover += qty * price;
}
cout << "turnover=" << turnover << "\n";
cout << "first_error=" << first_error << "\n";
cout << "stock=";
bool first = true;
for (const auto& entry : stock) {
if (entry.second <= 0) {
continue;
}
if (!first) {
cout << ',';
}
first = false;
cout << entry.first << ':' << entry.second;
}
if (first) {
cout << "EMPTY";
}
cout << "\n";
return 0;
}