如何找到“n”使用C ++在字符串中不重复的字符? [英] How to find "n" th non repeating character in the string using C++?

查看:65
本文介绍了如何找到“n”使用C ++在字符串中不重复的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不使用任何预定义方法的情况下在字符串中找到n个非重复字符(例如:字符串中的第3个非重复字符)。



我尝试了什么:



我尝试使用字符数组,但我无法增加其值人物存在。给我一些解决方案

Hi, I want to find the "n"th non-repeating character in the string(Ex: 3rd non-repeating character in the string) without using any predefined methods.

What I have tried:

I tried with character array but I can't able to increment the value of the character present. Give me some solutions

推荐答案

引用:

我试过字符数组但是我无法增加现有角色的值。

I tried with character array but I can't able to increment the value of the character present.



显示你的代码。



我们不做你的HomeWork。

HomeWork不会在乞求别人做你的工作时测试你的技能,它会让你思考并帮助你的老师检查你对你所学课程的理解。还有你在应用它们时遇到的问题。

你的任何失败都会帮助你的老师发现你的弱点并设定补救措施。

你的任何失败都会帮助你了解什么有效,什么无效,被称为'试错'学习。

所以,试一试,重读课程并开始工作。如果您遇到特定问题,请展示您的代码并解释这个问题,我们可能会提供帮助。


Show your code.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.


这是您的作业,所以您将无法获得代码!



但是,这就是我的方法:首先计算字符数,然后将计数存储在一个数组中,该数组中包含每个可能字符的空格。这很简单,只需输入一次。每次找到一个新值(即它的计数为零)都会将该位置存储在一个单独的数组中。

现在你有两个数组和输入数据:它很容易找到n th singleton - count数组为它保存一个。它的位置在另一个数组中。



我实际上是如何设置一个结构来保存char,位置和计数,并且只有一个数组而不是上面的两个数组。
THis is your homework, so you'll get no code!

But, this is how I'd do it: Start by counting the characters, and storing the counts in an array which has space for each possible character. That's trivial, and takes a single pass through the input. Each time you find a new value (i.e. it has a zero count) store the location in a separate array.
You now have two arrays, and the input data: it's simple to find the "n"th singleton - the count array holds a one for it. And it's location is in the other array.

How I'd actually do it is to set up a struct to hold the char, the location, and the count, and have a single array of those instead of the two arrays above.


这篇关于如何找到“n”使用C ++在字符串中不重复的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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