Given a string of digits, remove trailing zeros from it.
Input : 00000123569 Output : 123569 Input : 000012356090 Output : 12356090
1) Count trailing zeros.
2) Use string erase function to remove characters equal to above count.
Below is C++ implementation.
This article is contributed by Prakhar Agrawal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Removing elements between the two zeros
- Remove Duplicate/Repeated words from String
- Remove all consecutive duplicates from a string using STL in C++
- std::string::crbegin() and std::string::crend() in C++ with Examples
- Check if given string is a substring of string formed by repeated concatenation of z to a
- Convert a floating point number to string in C
- How to split a string in C/C++, Python and Java?
- C++ string class and its applications
- Different methods to reverse a string in C/C++
- C++ String Class and its Applications | Set 2
- Converting string to number and vice-versa in C++
- Removing spaces from a string using Stringstream
- How to convert C style strings to std::string and vice versa?
- std::string class in C++
- Counts of distinct consecutive sub-string of length two using C++ STL
- Raw string literal in C++
- Character replacement after removing duplicates from a string
- Write your own strlen() for a long string padded with '\0's
- 5 Different methods to find length of a string in C++
- Program to extract words from a given String