Skip to content

Instantly share code, notes, and snippets.

@domfarolino
Created August 23, 2016 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domfarolino/12ff9e31064002e672a4677f5d133b8d to your computer and use it in GitHub Desktop.
Save domfarolino/12ff9e31064002e672a4677f5d133b8d to your computer and use it in GitHub Desktop.
vector<int> multiplyVectorByInteger(const vector<int>& numVector, int n) {
vector<int> returnVec(numVector.size());
int carry = 0;
for (int i = 0; i < numVector.size(); ++i) {
returnVec[i] = (numVector[i]*n + carry) % 10;
carry = (numVector[i]*n + carry) / 10;
}
while (carry) {
returnVec.push_back(carry%10);
carry /= 10;
}
return returnVec;
}
int main() {
vector<int> output = {1};
int n;
cin >> n;
//....
while (n) {
output = multiplyVectorByInteger(output, n);
n--;
}
//....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment