Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace SandBox
- {
- public class Program
- {
- static void Main(string[] args)
- {
- string guessedWord = Console.ReadLine();
- string attempt = Console.ReadLine();
- if (attempt != null && guessedWord != null)
- {
- int N = guessedWord.Length;
- HashSet<int> lettersUsedNumbers = new HashSet<int>();
- string[] answer = new string[N];
- Dictionary<char, int> countLetters = new Dictionary<char, int>();
- for (int i = 0; i < N; i++)
- {
- if (countLetters.ContainsKey(guessedWord[i]))
- {
- countLetters[guessedWord[i]]++;
- }
- else
- {
- countLetters.Add(guessedWord[i], 1);
- }
- if (guessedWord[i] == attempt[i])
- {
- answer[i] = "correct";
- countLetters[guessedWord[i]]--;
- }
- }
- for (int i = 0; i < N; i++)
- {
- if (guessedWord[i] != attempt[i])
- {
- if (countLetters.ContainsKey(attempt[i]) && countLetters[attempt[i]] > 0 && guessedWord[i] != attempt[i])
- {
- answer[i] = "present";
- countLetters[attempt[i]]--;
- }
- else
- {
- answer[i] = "absent";
- }
- }
- }
- for (int i = 0; i < N; i++)
- {
- Console.WriteLine(answer[i]);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement