// UVa 11491 - Erasing and Winning #include <stdio.h> #include <list> using namespace std; int main() { int digit_count, to_delete; scanf("%d %d\n", &digit_count, &to_delete); while (digit_count || to_delete) { list<char> digits; digits.push_back('9' + 1); for (int i = 0; i < digit_count; i++) { char ch; scanf("%c", &ch); digits.push_back(ch); } digits.push_back('0' - 1); std::list<char>::iterator it1 = digits.begin(), it2 = it1; it2++; while (it2 != digits.end() && to_delete > 0) { while (*it1 < *it2 && to_delete > 0) { it1 = digits.erase(it1); it1--; to_delete--; } it1++; it2++; } while (to_delete) { digits.pop_back(); to_delete--; } digits.pop_front(); digits.pop_back(); for (it1 = digits.begin(); it1 != digits.end(); ++it1) printf("%c", *it1); printf("\n"); scanf("\n%d %d\n", &digit_count, &to_delete); } return 0; }
Thursday, April 23, 2015
UVa 11491 - Erasing and Winning
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment