题解 | #明明的随机数#

字符串分隔

http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7

我的做法是先补足再遍历

using System;
using System.Linq;

namespace App {
public class Test {
    public static void Main() {
        string input;
        while ((input = Console.ReadLine()) != null) {
            int length = input.Length;
            int lack = 8 - length % 8;
            if (lack > 0 && lack < 8) {
                for (int i = 0; i < lack; i++) {
                    input += "0";
                }
            }
            int lineNum = input.Length / 8;
            for (int j = 0; j < lineNum; j++) {
                string curLineStr = input.Substring(8 * j, 8);
                Console.WriteLine(curLineStr);
            }
        }
        return;
    }
}
}

全部评论

相关推荐

4 1 评论
分享
牛客网
牛客企业服务