Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <math.h>
- using namespace std;
- int printMaxNum(int num);
- int main() {
- ifstream inFile;
- inFile.open("acces.in");
- int value;
- int numberOfTotalDigits, numberOfDigitsToBeRemoved;
- inFile >> numberOfTotalDigits >> numberOfDigitsToBeRemoved;
- //Generate frequency array
- int count[10] = {0}; // last part simply puts 0 for eeach position
- //Read remaining values from the file
- while (inFile >> value) {
- count[value]++;
- }
- int result = 0, multiplier = 1; // here multiplier means unitati, zeci, sute..etc
- for (int i = 0; i <= 9; i++)
- {
- while (count[i] > 0)
- {
- result = result + (i * multiplier);
- count[i]--;
- multiplier = multiplier * 10;
- }
- }
- //After we have the greatest number that can be obtained, simply discard its last m numbers;
- int truncatedResult = result / pow(10, numberOfDigitsToBeRemoved);
- cout << truncatedResult;
- return 0;
- }
Add Comment
Please, Sign In to add comment