[go: up one dir, main page]

0% found this document useful (0 votes)
4 views2 pages

Pranav

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Pranav

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

# include <unordered_map>
# include <vector>
# include <set>

using namespace std;


int main() {
// you can write to stdout for debugging purposes, e.g.
// std::cout << "This is a debug message" << std::endl;
string correct_word="";
string guessed_word = "";
unordered_map<char,set<int>> correct_word_map;
unordered_map<char,set<int>> guessed_word_map;

for(int i=0;correct_word[i] !='\0';i++)


{
if(correct_word_map.find(correct_word[i])==correct_word_map.end())
{
correct_word_map.insert(correct_word[i],{i});
}

correct_word_map[correct_word[i]].insert(i);
}

for(int i=0;guessed_word[i] !='\0';i++)


{
if(guessed_word_map.find(guessed_word[i])==guessed_word_map.end())
{
guessed_word_map.insert(guessed_word[i],{i});
}

guessed_word_map[guessed_word[i]].insert(i);
}

for(auto i: guessed_word_map)
{
char considered_char = i.first;
set<int> considered_pos = i.second;

if(correct_word_map.find(considered_char)==correct_word_map.end())
{
// "non-existing";
}
else
{
set<int> correct_pos = correct_word_map[considered_char];
// if(considered_pos.size()!=correct_pos.size())
// {
// // "non-existing";

// }
for(auto j: considered_pos)
{
if(correct_pos.find(j)!=correct_pos.end())
{
return "correct";
}
else
{
return "misplaced";
}
}
}
}
return 0;
}

// INPUT : 0 1 2 3 4 5 6

// output: 51 0 50 1

// JUNGLEE

// tinHLUE

// able
// ELSE

// cORrect_word_map
// A -> 0
// B-> 1
// L->2
// E-> 3,6,8

// Guessed word map


// E->0,1,2,7,9
// L->1
// S->2

You might also like