From 3cd582c6e85f38a9d440a9ada5aed58def41d2a1 Mon Sep 17 00:00:00 2001 From: pompydev Date: Thu, 6 Jun 2024 00:18:52 +0900 Subject: [PATCH] feat: basic fast io for C++ --- cpp/a.cpp | 22 +++++++++++++++++++++- cpp/cpp.justfile | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/cpp/a.cpp b/cpp/a.cpp index 778ad69..5d3fbc3 100644 --- a/cpp/a.cpp +++ b/cpp/a.cpp @@ -4,9 +4,29 @@ #pragma GCC optimize("Ofast") #pragma GCC optimization("unroll-loops") +#define N 3 + using namespace std; int main() { - cout << "Hello, C++!\n"; + // faster IO + ios::sync_with_stdio(false); + cin.tie(NULL); + + int sum = 0; + int nums[N]; + + for (int i = 0; i < N; i++) + { + cin >> nums[i]; + sum += nums[i]; + + cout << nums[i]; + + if (i < N - 1) + cout << " + "; + } + + cout << " = " << sum << "\n"; } diff --git a/cpp/cpp.justfile b/cpp/cpp.justfile index 0e14e02..54b8878 100644 --- a/cpp/cpp.justfile +++ b/cpp/cpp.justfile @@ -5,4 +5,4 @@ ./cpp/a < ./input.txt @bench-cpp: build-cpp - hyperfine './cpp/a < ./input.txt' \ No newline at end of file + hyperfine './cpp/a < ./input.txt'