如何编写以下程序的程序代码? [英] How to write program code for below program?

查看:79
本文介绍了如何编写以下程序的程序代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入:aaabbcddd

输出:a3b2c1d4





我知道使用LINQ编码,但如何在C#中使用循环的代码?

解决方案

我们不做你的作业:它是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是你想的很难!



和面试问题是你的功课 - 因为这是微不足道的。

1)创造一个当前char变量和计数。将当前设置为除第一个字符以外的任何内容,并将计数设置为负值。

2)循环。

2.1)当前是否相同字符串中的当前字符?

2.1.1)如果是,则增加计数

2.1.2)如果不是,请检查计数

2.1.2.1)如果是正面,打印当前,打印计数,

2.1.2.2)否则,什么都不做

2.1.3)设置当前字符串中的当前值,将计数设置为零。

2.2)移动到字符串中的下一个字符。



简单!

Input: aaabbcddd
Output: a3b2c1d4


I know to code using LINQ but how to code using loop in C#?

解决方案

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

And "interview questions" are your homework - because this is trivial.
1) create a "current char" variable, and a "count". Set "current" to anything except teh first character, and "count" to a negative value.
2) Loop.
2.1) Is "current" the same at the current character in the string?
2.1.1) If it is, increase the count
2.1.2) If it isn't, check the count
2.1.2.1) if it's positive, print "current", print the count,
2.1.2.2) Otherwise, do nothing
2.1.3) Set the current to the current in the string, set the count to zero.
2.2) Move to next character in string.

Simples!


这篇关于如何编写以下程序的程序代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆