diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2022-11-07 13:29:00 +0200 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2022-11-07 13:29:00 +0200 |
commit | 4edd3ef32bf3cac07eea48477aa369dddb4a2b30 (patch) | |
tree | 56143ef00cfeb289b2470bb7adadb4672d50686f | |
parent | cdb159c137a82fd9756300dd6d1cba68f509b606 (diff) | |
download | gcd-4edd3ef32bf3cac07eea48477aa369dddb4a2b30.tar.gz |
C++: format with clang-format
-rw-r--r-- | gcd.cpp | 70 |
1 files changed, 32 insertions, 38 deletions
@@ -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; } - |