Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- public static bool AandB(string st, int start, int finish) //ex21
- {
- string sub = st.Substring(start, finish - start);
- int countA = 0, countB = 0;
- for (int i = 0; i < sub.Length; i++)
- if (sub[i] == 'a')
- countA++;
- else if (sub[i] == 'b')
- countB++;
- return countA == countB;
- }
- public static string ReplaceWith(string text, string replaced, string with) //ex12
- {
- text = text.Replace(replaced, with);
- return text;
- }
- public static int CountApps(string text, string word) //ex10
- {
- int count = 0;
- for (int i = 0; i < text.Length - word.Length; i++)
- {
- if (text.IndexOf(word, i) > 0)
- count++;
- }
- return count;
- }
- public static int StartsWith(string[] a, string s) //ex9
- {
- int count = 0;
- for (int i = 0; i < a.Length; i++)
- if (a[i].IndexOf(s) == 0)
- count++;
- return count;
- }
- static void Main(string[] args) //commented out - ex9's main
- {
- int count = 0, kMax = 6;
- string st;
- st = Console.ReadLine();
- for (int i = 0; i < st.Length - 2; i++)
- {
- if (st.Length - i < 6)
- kMax = st.Length - i;
- for (int k = 2; k < kMax; k++)
- {
- if (AandB(st, i, i + k))
- count++;
- }
- }
- Console.WriteLine("Amount of substrings: " + count);
- //string[] arr = new string[5];
- //string st;
- //for (int i = 0; i < arr.Length; i++)
- //{
- // Console.WriteLine("Word no. " + (i + 1));
- // arr[i] = Console.ReadLine();
- //}
- //Console.WriteLine("Word: ");
- //st = Console.ReadLine();
- //Console.WriteLine(StartsWith(arr, st) + " words start with " + st);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement