From 82320e4a5331188fe48b5b68b70f297fc167ca76 Mon Sep 17 00:00:00 2001 From: JesseChen Date: Wed, 27 Apr 2022 21:06:11 +0800 Subject: [PATCH] =?UTF-8?q?314=20855447=20=E9=99=B3=E5=BB=BA=E5=BB=B7=2020?= =?UTF-8?q?220421=20CodeWars=E4=BD=9C=E6=A5=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 855447/Sum of Digits Digital Root.cpp | 19 +++++++++++++++++++ 855447/find-the-odd-int.cpp | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 855447/Sum of Digits Digital Root.cpp create mode 100644 855447/find-the-odd-int.cpp diff --git a/855447/Sum of Digits Digital Root.cpp b/855447/Sum of Digits Digital Root.cpp new file mode 100644 index 0000000..5896c56 --- /dev/null +++ b/855447/Sum of Digits Digital Root.cpp @@ -0,0 +1,19 @@ +using namespace std; +int digital_root(int n) +{ + int num; + num=0; + while(true){ + if (n/10!=0){ + num+=n%10; + n=n/10; + }else if ((n+num)>10){ + n+=num; + num=0; + }else if ((n+num)<10) { + num+=n; + break; + } +} + return num; +} \ No newline at end of file diff --git a/855447/find-the-odd-int.cpp b/855447/find-the-odd-int.cpp new file mode 100644 index 0000000..d50ccec --- /dev/null +++ b/855447/find-the-odd-int.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; +int findOdd(const vector numbers){ + int x = 0,ans = 0; + for(int i = 0 ; i < numbers.size() ; i++){ + x=0; + for (int j = 0 ;j < numbers.size() ; j++){ + if (numbers[i] == numbers[j]){ + x += 1; + } + } + if (x % 2 != 0){ + ans=numbers[i]; + } + } +return ans; +} \ No newline at end of file