找子串
Time Limit:1000MS Memory Limit:65536K
Total Submit:170 Accepted:61
Description
给定原子串和目标子串,要你求得目标子串在原子串当中出现的次数。
Input
多组测试数据,每组测试数据第一行是原子串,第二行是目标子串
子串长度不会超过100.
Output
输出目标子串在原子串当中出现的次数。
Sample Input
abc123abc
abc
aabcCdeAbcAbcdeccde
cde
Sample Output
2
2
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);
}
}
}
}