Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commitc38db883a5c2268f6c44acea031d57264db9f5f5 (patch)
Author
 Angel Dimitriev <achi_d@abv.bg>
2021-12-05 02:57:58 -0500
Committer
 GitHub <noreply@github.com>
2021-12-05 02:57:58 -0500
Filesb2c61c48371f3fecf3d182326b1f18f7d090a8eb
Introduction_to_programming_FMI-c38db883a5c2268f6c44acea031d57264db9f5f5.tar
Introduction_to_programming_FMI-c38db883a5c2268f6c44acea031d57264db9f5f5.tar.gz
Introduction_to_programming_FMI-c38db883a5c2268f6c44acea031d57264db9f5f5.zip
Parent308f7156cbdf4a3f7dc4239d00e82d475a55be4d (diff)
Create task1.cpp
1 files changed, 71 insertions, 0 deletions
-rw-r--r--Utils/SI_K1/task1.cpp71
diff --git a/Utils/SI_K1/task1.cpp b/Utils/SI_K1/task1.cpp
new file mode 100644
index 0000000..d06b550
--- /dev/null
+++ b/Utils/SI_K1/task1.cpp
@@ -0,0 +1,71 @@
+#include <iostream>
+using namespace std;
+
+//Sem 4, task 6
+unsigned reverse(unsigned int n)
+{
+ unsigned int result = 0;
+
+ while (n != 0)
+ {
+ int lastDigit = n % 10;
+ (result *= 10) += lastDigit;
+ n /= 10;
+ }
+
+ return result;
+}
+
+bool isSuffix(unsigned int n, unsigned int k)
+{
+ if (k == 0 && (n % 10 != 0))
+ return false;
+
+ while (k != 0)
+ {
+ int lastDigitOfN = n % 10;
+ int lastDigitOfK = k % 10;
+
+ if (lastDigitOfN != lastDigitOfK)
+ return false;
+
+ n /= 10;
+ k /= 10;
+ }
+
+ return true;
+}
+
+bool isPrefix(unsigned int n, unsigned int k)
+{
+ return isSuffix(reverse(n), reverse(k));
+}
+
+bool isInfix(unsigned int n, unsigned int k)
+{
+ if (n == 0 && k == 0)
+ return true;
+
+ while (n > 0)
+ {
+ if (isSuffix(n, k))
+ return true;
+ n /= 10;
+ }
+ return false;
+}
+///// end sem4 task6
+
+//Solution
+
+bool task1(unsigned n, unsigned k)
+{
+ n = reverse(reverse(n/10) / 10); //remove the first and the last digit of n.
+ return isInfix(n,k); //call the function from the already solved task
+}
+
+
+int main()
+{
+ cout << task1(1234,12);
+}