网站运营系统,建网站挣钱 优帮云,线上推广软件,网络推广公司介绍【算法分析】 ● 前导 0#xff08;Leading Zero#xff09;指的是出现在数字或字符串开头、且在第一个非 0 数字之前的所有 0。 例如#xff0c;00123 的前导 0 是开头的两个 0#xff0c;去除后应为 123#xff1b;000 没有非 0 数…【算法分析】●前导 0Leading Zero指的是出现在数字或字符串开头、且在第一个非 0 数字之前的所有 0。例如00123 的前导 0 是开头的两个 0去除后应为 123000 没有非 0 数字去除前导 0 后通常保留一个 0而非空字符串12030 没有前导 0。【算法代码】#include bits/stdc.h using namespace std; string RLZ(string str) { //Remove Leading Zeros int p0; //pos if(str[0]-) p1; while(pstr.size() str[p]0) { str.erase(p,1); //Delete str[p] } if(str-) return -0; if(str.empty()) return 0; return str; } int main() { int T; cinT; while(T--) { string s; cins; coutRLZ(s)endl; } return 0; } /* in: 6 00123 000 12030 -00123 -000 001020 out: 123 0 12030 -123 -0 1020 */【参考文献】https://blog.csdn.net/hnjzsyjyj/article/details/157836967