Created
November 19, 2022 16:55
-
-
Save warhammer327/3c67d2b0e1c9d27a8b74027bb54a430a to your computer and use it in GitHub Desktop.
Airwrk - coding test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <bits/stdc++.h> | |
| #define debug(x) printf("-----------------%d\n", x); | |
| #define LEN sizeof(a) / sizeof(a[0]) | |
| #define MEM(arr, k) memset(arr, k, sizeof arr) | |
| #define input freopen("01input.txt", "r", stdin) | |
| #define output freopen("01output.txt", "w", stdout) | |
| #define go \ | |
| ios_base::sync_with_stdio(false); \ | |
| cin.tie(0); \ | |
| cout.tie(0); | |
| using namespace std; | |
| int X8[] = {0, 1, 0, -1, 1, -1, 1, -1}; | |
| int Y8[] = {1, 0, -1, 0, 1, -1, -1, 1}; | |
| int X4[] = {1, -1, 0, 0}; | |
| int Y4[] = {0, 0, 1, -1}; | |
| vector<int> runningsum(int nums[], int len){ | |
| int ans[len]; | |
| ans[0] = nums[0]; | |
| for (int i = 1; i < len; i++) | |
| { | |
| ans[i] = ans[i-1] + nums[i]; | |
| } | |
| //putting ans array in vector as the example said to return vector | |
| vector<int> ans_vec; | |
| for (int i = 0; i < len; i++) | |
| { | |
| ans_vec.push_back(ans[i]); | |
| } | |
| return ans_vec; | |
| } | |
| int main() | |
| { | |
| int num[] = {1, 2, 3, 4}; | |
| int len = sizeof(num) / sizeof(num[0]); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<bits/stdc++.h> | |
| #define debug(x) printf("-----------------%d\n",x); | |
| #define LEN sizeof(a)/sizeof(a[0]) | |
| #define MEM(arr,k) memset(arr,k,sizeof arr) | |
| #define input freopen("01input.txt","r",stdin) | |
| #define output freopen("01output.txt","w",stdout) | |
| #define go ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); | |
| using namespace std; | |
| int X8[] = {0, 1, 0, -1, 1, -1, 1, -1}; | |
| int Y8[] = {1, 0, -1, 0, 1, -1, -1, 1}; | |
| int X4[] = {1, -1, 0, 0}; | |
| int Y4[] = {0, 0 , 1, -1}; | |
| bool solve(int n) | |
| { | |
| string s = to_string(n); | |
| string copy_of_s = s; | |
| reverse(copy_of_s.begin(), copy_of_s.end()); | |
| //if reversed string starts with zero, it won't be possible to get back the original string | |
| if(copy_of_s[0]=='0') | |
| return false; | |
| return true; | |
| } | |
| int main(){ | |
| if(solve(123)) | |
| cout << "true"; | |
| else | |
| cout << "false"; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<bits/stdc++.h> | |
| #define debug(x) printf("-----------------%d\n",x); | |
| #define LEN sizeof(a)/sizeof(a[0]) | |
| #define MEM(arr,k) memset(arr,k,sizeof arr) | |
| #define input freopen("01input.txt","r",stdin) | |
| #define output freopen("01output.txt","w",stdout) | |
| #define go ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); | |
| using namespace std; | |
| int X8[] = {0, 1, 0, -1, 1, -1, 1, -1}; | |
| int Y8[] = {1, 0, -1, 0, 1, -1, -1, 1}; | |
| int X4[] = {1, -1, 0, 0}; | |
| int Y4[] = {0, 0 , 1, -1}; | |
| int sumofdigit(int n) | |
| { | |
| int sum = 0; | |
| //taking the last digit, adding it to sum then dividing n by 10 to mod the next digit | |
| while(n>0){ | |
| sum += n % 10; | |
| n = n / 10; | |
| } | |
| return sum; | |
| } | |
| int solve(int n) | |
| { | |
| while(n>9) | |
| { | |
| n = sumofdigit(n); | |
| } | |
| return n; | |
| } | |
| int main(){ | |
| cout << solve(38); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment