-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLetters_In_Words_2.cs
More file actions
36 lines (36 loc) · 1.33 KB
/
Letters_In_Words_2.cs
File metadata and controls
36 lines (36 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// напишите функцию, которая получает на вход два слова.
// Необходимо, чтобы подпрограммая возвращала только те буквы слов, которые встречаются в одном слове, но не в обоих
namespace eks
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Введите два слова");
string word1 = Console.ReadLine();
string word2 = Console.ReadLine();
Console.WriteLine(DifferentLetters(word1, word2));
Console.ReadKey();
}
static string DifferentLetters(string word1, string word2)
{
word1 = new string(word1.Distinct().ToArray());
word2 = new string(word2.Distinct().ToArray());
string answer = word1 + word2;
foreach (char letter in word1)
{
if(word2.Contains(letter))
{
answer = answer.Remove(answer.IndexOf(letter), 1);
answer = answer.Remove(answer.IndexOf(letter), 1);
}
}
return (answer);
}
}
}