zoukankan      html  css  js  c++  java
  • 一道C#面试题

    C#面试题统计"0"字符数量,并将统计数字插入到字符中。要求:
    输入:
    rnbakabnr/000000000/0c00000c0/p0p0p0p0p/000000000/000000000/P0P0P0P0P/0C00000C0/000000000/RNBAKABNR
    输出:
    rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR

    答案:

    //递归算法

      private string ProssStr(string tempStr)
            {
                string tempAll = "";
                int j0 = tempStr.IndexOf('0');
                if (j0 > -1)
                {
                    int j1 = 0;
                    for (int i = 0; i < tempStr.Length - j0; i++)
                    {
                        string k2 = tempStr.Substring(j0 + i, 1);
                        if (k2 == "0")
                        {
                            j1 = j1 + 1;
                        }
                        else
                        {
                            break;
                        }
                    }
                    string tempStr1 = tempStr.Remove(j0, j1).Insert(j0, j1.ToString());
                    tempAll = ProssStr(tempStr1);
                }
                else
                {
                    tempAll = tempStr;
                }
                return tempAll;
            }

    调用:

     string tempStrAll = "";
                string s = "rnbakabnr/000000000/0c00000c0/p0p0p0p0p/000000000/000000000/P0P0P0P0P/0C00000C0/000000000/RNBAKABNR";//输入
                tempStrAll = ProssStr(s);//执行算法

    输出到变量tempStrAll:

    rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR

  • 相关阅读:
    很火的华为太空表网站源码
    exists用法 exists用法讲解
    mysql 建立索引在on 从句中_MySQL优化
    mysql on 条件会走索引吗
    【算法理论】动归入门[C语言描述]
    机器学习基础考试复习
    【基础知识】深度学习500问之生成对抗网络
    【王道数据结构】《王道数据结构》课后代码题汇总
    【C语言实现】数据结构算法题及答案
    【题目归档】考研数据结构算法题目归档
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/2981243.html
Copyright © 2011-2022 走看看