题解 | #小乐乐改数字#

小乐乐改数字

https://www.nowcoder.com/practice/fcd30aac9c4f4028b23919a0c649824d

using System;

public class Program {
    public static void Main() {
        string Input = Console.ReadLine();
        string OutPut = "";

        for (int i = 0; i < Input.Length; i++) {
            int Num = Convert.ToInt32(Input[i]);
            //如果是偶数
            if (Num % 2 == 0) {
                OutPut += "0";
            } else {
                OutPut += "1";
            }
        }

        //处理输出结果
        string result = "";
        //第一个1是否出现
        bool isShow = false;
        for (int i = 0; i < OutPut.Length; i++) {
            //找出第一个1出现的位置,如果没有,输出结果则为0
            if (OutPut[i] == '0') {
                if (!isShow)
                    continue;
                else
                    result += '0';
            } else if (OutPut[i] == '1') {
                result += "1";
                isShow = true;
            }
        }

        //全是0的情况
        if (result == "")
            result = "0";

        Console.WriteLine(result);
    }
}

全部评论

相关推荐

机械打工仔:有说的你怀疑一下就行了,直接问也太实诚了
点赞 评论 收藏
分享
码农索隆:竞争压力小,就你一个不用卷
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务