当前位置:三九宝宝网 → 宝宝教育 → 写作范文 → 正文

求字符串统计的算法有代码更好谢啦

更新:12-28 整理:39baobao.com
字体:

[采取不同的教学方式,设置算法情境,在互动中学习]我们古人都说要因此施教的,所以现在更应该这样做了,下面我们就来看看这篇采取不同的教学方式,设置算法情境,在互动中学习吧。 6岁左右的幼儿,抽象逻辑思维开始发展,探索欲增强,语言...+阅读

参考网上的代码用C#写的:调试成功,你先琢磨琢磨:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace 求字符串重复

{

// 有字符串: qabaabbwerabtyababuiopasdfghjkabl,请写一段程序,找出重复出现的字符串(长度大于 1 的连续字符组合),以及他们出现的次数。通过控制台打印出来。比如:

//ab,6

//aba,2

//ba,2

class Program

{

static void Main(string[] args)

{

string str = "qabaabbwerabtyababuiopasdfghjkabl";

CountRepeat(str);

}

static void CountRepeat(string str)

{

for (int start = 0; start < str.Length; start++)

{

for (int len = 2; len < str.Length - start + 1; len++)

{

string pi = str.Substring(start, len);

if (str.Substring(0, start).Contains(pi))

{

continue;

}

int count = CountNumber(str, pi);

if (count > 1)

{

Console.WriteLine("{0}重复{1}次",pi,count);

}

}

}

}

static int CountNumber(string str, string pi)

{

int count = 0;

int start = -1;

while (true)

{

int index = str.Substring(start + 1).IndexOf(pi);

if (index == -1)

{

break;

}

count++;

start += index + 1;

}

return count;

}

}

}

本文地址:https://www.39baobao.com/show/33_17029.html

以上内容来自互联网,请自行判断内容的正确性。若本站收录的信息无意侵犯了贵司版权,请联系我们,我们会及时处理和回复,谢谢.

以下为关联文档:

java统计字符串的连续子串是回文串的个数import java.util.ArrayList; import java.util.List; public class Palindrome { /* 找出一个字符串中最长的回文子串 * 从字符串中第i个字符开始的所有非空回文子串的个数...

Java题统计字符串中字母的个数public static int countLetters(String s) {String str =s; while (!"".equals(str)) { String c = str.substring(0, 1); String tempStr = str.replace(c, ""); System.out.p...

java统计字符串中每个字母有多少个如下代码提供了三种方式统计一个字符串中出现的大小写字母和其他字符: class Test{ publicstatic void main(String[] args) { String str = "abAM1,!23"; int cntU = 0; //大写...

使用下列方法头编写一个方法统计字母在字符串中出现的个数判断一下就好了 public class Text{ /** * param args * throws IOException */ public static void main(String[] args) { System.out.println(countLetters("java 2008"));...

java统计字符串中字母的个数如何修改import java.util.Scanner; /** * 统计字符串中数字,字母,空格,其他字符的个数 * author Administrator * */ public class Data01 { public static void main(String[] args)...

java输入字符串统计字母单词数字句子个数1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 importjava.util.*; classTest{ publicstaticvoidmain(String[] args){ Scanner s=newScanner(System.in); String str=" "+s.nex...

java编程:输入一个字符串计算字符串中所包含的字母个数数字public class Practise1 { /** * param args */ public static void main(String[] args) { Practise1.tongJi("afajofiGILB76097你好世界"); } public static void tongJi(Str...

Java键盘输入一个字符串分别统计出该字符串中所有数字大写英参考代码如下: #include<stdio.h> int main() { char ch; int A,a,n,other; A=a=n=other=0; while((ch=getchar())!='\n'){ if(ch>='a'&ch<='z') ++a; else if(ch>='A'&ch<='...

C输入一个字符串统计出某个指定的字符在该字符串中出现的次#include<iostream> #include<string> using namespace std; void main() { char *p,a[81]; int n,i; cout<&lt;"请输入一个字符串:"<<endl; cin.getline(a,81); char search; c...