1084 -- 找子串

来源:互联网 发布:嵌入式好还是java好 编辑:程序博客网 时间:2024/05/18 02:42

找子串

Time Limit:1000MS  Memory Limit:65536K
Total Submit:170 Accepted:61

Description

给定原子串和目标子串,要你求得目标子串在原子串当中出现的次数。

Input

多组测试数据,每组测试数据第一行是原子串,第二行是目标子串
子串长度不会超过100.

Output

输出目标子串在原子串当中出现的次数。

Sample Input

abc123abcabcaabcCdeAbcAbcdeccdecde

Sample Output

22

Source

    using System;    using System.Collections.Generic;    using System.Linq;    using System.Text;    namespace AK1084 {        class Program {            static void Main(string[] args) {                string s;                while ((s = Console.ReadLine()) != null) {                    int count = 0;                    string b = Console.ReadLine();                    for (int i = 0; i < s.Length - b.Length + 1; i++) {                        string sb = s.Substring(i, b.Length);                        if (sb.Equals(b))                            count++;                    }                    Console.WriteLine(count);                }            }        }    }


0 0
原创粉丝点击