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;
- using System.Threading.Tasks;
- namespace RecusionAnagram
- {
- class Program
- {
- static string first;
- static string second;
- static bool anagrams = true;
- static void Main(string[] args)
- {
- Console.WriteLine("Enter first string: ");
- first = Console.ReadLine();
- Console.WriteLine("Enter second string: ");
- second = Console.ReadLine();
- permute(first.ToCharArray(), 0, first.Length - 1);
- if (anagrams)
- {
- Console.WriteLine("Strings are anagrams.");
- }
- else
- {
- Console.WriteLine("Strings are not anagrams.");
- }
- }
- static void permute(char[] a, int i, int n)
- {
- int j;
- if (i == n)
- if (a.ToString() == second)
- {
- anagrams = true;
- }
- else
- {
- for (j = i; j <= n; j++)
- {
- char temp = a[i];
- a[i] = a[j];
- a[j] = temp;
- permute(a, i+1, n);
- temp = a[i];
- a[i] = a[j];
- a[j] = temp;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement