题解 | #字符串分隔#

字符串分隔

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

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Text;


public class Program {
    public static void Main() {
        string line;
        while ((line = System.Console.ReadLine ()) != null) { // 注意 while 处理多个 case

            ProcessString(line);
        }


    }

    private static void ProcessString(string str)
    {

        StringBuilder sb = new StringBuilder();
        int index = 0;
        char [] charArray = str.ToCharArray();


        foreach(var ch in charArray)
        {
            sb.Append(ch);
            index++;
            if(index ==8)
            {
                System.Console.WriteLine(sb.ToString());
                sb.Clear();
                index = 0;
            }
        }
        if(sb.Length<8&&sb.Length>=1)
        {
              int len = sb.Length;
             for(int j=0;j<(8-len);j++)
             {
                 sb.Append('0');
             }
            string result = sb.ToString();
             System.Console.WriteLine(result);
        }


    }
}
全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

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