Aliens Invasion- Editorial || ALNIVN

PROBLEM LINK: Aliens Invasion | CodeChef

Problem Code: Aliens Invasion | CodeChef

Practice: Practice | CodeChef

Contest : Campus Code August Edition Coding Competition | CodeChef

Author: Codechef Adgitm Chapter : https://www.codechef.com/users/test_account_9
Tester: Codechef Adgitm Chapter : https://www.codechef.com/users/test_account_9
Editorialist: Codechef Adgitm Chapter : https://www.codechef.com/users/test_account_9

DIFFICULTY:

Easy

PREREQUISITES:

Looping.

PROBLEM:

Aliens have invaded the world, they have given you a puzzle word. Aliens want to find a human whose name is a rotation of the given word. if you show them a person who satisfy the given criteria they will leave else the world will be destroyed. given name of everyone around you find whether you can save the world by presenting the human.

EXPLANATION:
compare and move to next index. With some extra conditions it can be solved.

SOLUTION:
C++:

#include<bits/stdc++.h>
using namespace std;

string rotation(string s){
int n = s.size();
string temp = “”;
for(int i=0; i<n-1; i++)
temp.push_back(s[i+1]);
temp.push_back(s[0]);
return temp;
}
int main(){
string s;
cin>>s;
vectorss;
int n=s.size();
string t;
while(cin>>t){
ss.push_back(t);
}
setse;
se.insert(s);
for(int i=0;i<n-1;++i){
string p=rotation(s);
se.insert(p);
}
for(int i=0;i<ss.size();++i){
if(se.find(ss[i])!=se.end()){
cout<<ss[i]<<" ";
}
}
return 0;
}