Created
December 17, 2014 15:26
-
-
Save sicknarlo/b7b3df2f829d0c3b2545 to your computer and use it in GitHub Desktop.
[HackerRank] Find Digits
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
| /* You are given an integer N. Find the digits in this number that exactly divide N and display their count. | |
| For N = 24, there are 2 digits - 2 & 4. Both these digits exactly divide 24. So our answer is 2. */ | |
| #include<iostream> | |
| #include<string> | |
| using namespace std; | |
| int main(){ | |
| int t; | |
| string value; | |
| int output[16]; | |
| cin >> t; | |
| for (int i = 0; i < t; i++){ | |
| int count = 0; | |
| long int stringAsInt = 0; | |
| cin >> value; | |
| stringAsInt = atoi(value.c_str()); | |
| for (int j = 0; j < value.length(); j++){ | |
| if (value[j] != '0'){ | |
| char test = value[j]; | |
| int charAsInt = test - '0'; | |
| if (stringAsInt % charAsInt == 0) | |
| count++; | |
| } | |
| } | |
| output[i] = count; | |
| } | |
| for (int k = 0; k < t; k++){ | |
| cout << output[k] << endl; | |
| } | |
| system("pause"); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment