summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2022-11-07 13:29:00 +0200
committerIgor Pashev <pashev.igor@gmail.com>2022-11-07 13:29:00 +0200
commit4edd3ef32bf3cac07eea48477aa369dddb4a2b30 (patch)
tree56143ef00cfeb289b2470bb7adadb4672d50686f
parentcdb159c137a82fd9756300dd6d1cba68f509b606 (diff)
downloadgcd-4edd3ef32bf3cac07eea48477aa369dddb4a2b30.tar.gz
C++: format with clang-format
-rw-r--r--gcd.cpp70
1 files changed, 32 insertions, 38 deletions
diff --git a/gcd.cpp b/gcd.cpp
index 659c77a..dfc2356 100644
--- a/gcd.cpp
+++ b/gcd.cpp
@@ -7,65 +7,59 @@
*
*
* To use GNU Multiple Precision Arithmetic Library:
- *
+ *
* # g++ -o gcd-cpp-gmp -DGMP -lgmpxx -lgmp gcd.cpp
* # ./gcd-cpp-gmp 1234567890987654321 987654321234567
* # 63
*
*/
-
#include <cstdlib>
#include <iostream>
-#include <vector>
#include <sstream>
+#include <vector>
using namespace std;
#ifdef GMP
- #include <gmpxx.h>
- typedef mpz_class Number;
+#include <gmpxx.h>
+typedef mpz_class Number;
#else
- typedef unsigned int Number;
+typedef unsigned int Number;
#endif // GMP
typedef vector<Number> Numbers;
-Number gcd(Number a, Number b)
-{
- Number c;
- while (b != 0) {
- c = b;
- b = a % b;
- a = c;
- }
- return a;
+Number gcd(Number a, Number b) {
+ Number c;
+ while (b != 0) {
+ c = b;
+ b = a % b;
+ a = c;
+ }
+ return a;
}
-Number gcd(const Numbers & ns)
-{
- Number r = 0;
- for(Numbers::const_iterator n = ns.begin(); n != ns.end(); ++n)
- r = gcd(*n, r);
- return r;
+Number gcd(const Numbers &ns) {
+ Number r = 0;
+ for (Numbers::const_iterator n = ns.begin(); n != ns.end(); ++n)
+ r = gcd(*n, r);
+ return r;
}
-
-int main (int argc, char *argv[])
-{
- if (argc > 1) {
- Numbers ns(argc - 1);
- for(int n = 1; n < argc; ++n) {
- stringstream str;
- str << argv[n];
- str >> ns[n-1];
- /* NOTE:
- * For GMP we can just assign: ns[n-1] = argv[n],
- * and sstream is not needed.
- */
- }
- cout << gcd(ns) << endl;
+int main(int argc, char *argv[]) {
+ if (argc > 1) {
+ Numbers ns(argc - 1);
+ for (int n = 1; n < argc; ++n) {
+ stringstream str;
+ str << argv[n];
+ str >> ns[n - 1];
+ /* NOTE:
+ * For GMP we can just assign: ns[n-1] = argv[n],
+ * and sstream is not needed.
+ */
}
- return EXIT_SUCCESS;
+ cout << gcd(ns) << endl;
+ }
+ return EXIT_SUCCESS;
}
-