×

# RIT03 - Editorial

Editorialist :- [http://www.codechef.com/users/dvlpr_expert]

DIFFICULTY :- Medium

PREREQUISITES :- Maths,String

PROBLEM :- The CS & IT Department students have been facing tough competitions from each other since ages, in being the best in research & innovation. This time CS Department is taken the edge over IT Department by designing a special weather predictor device which inputs previous years data and perform analysis over it to give a prediction of current weather condition. This device needs a unique string code to be unlocked and activated, which is always kept safe with the Head Of Department's Computer. But this time IT Dept. students are able to hack the code over the network and they have distorted the original code by removing some characters and by replacing some characters. The CS Department has to rebuild the code in order to make their device work. You are given the actual code and the distorted code, you have to find the minimum number of operations to be performed to rebuild the distorted code. An operation can be (1) Adding one or more character(s) (2) Replacing one character with another. Adding one or more character does not consume time whereas replacing a single character require one unit of time. You have to find out the minimum unit of time in which CS Dept. can rebuild the distorted code.

EXPLANATION :-

You are having 2 strings, out of which one is original string and the other one is having some characters changes from the original string and your task is to get the original string from the other distorted string by adding a characters or replacing characters.

SOLUTION :-

# include<bits stdc++.h="">

using namespace std;

int main() {

int t; //Number of test case

cin "t";

while(t--)      //Loop till the test case exists
{

string x,y;   //Accepting strings

cin "x";

cin "y";

int ct=0;     //declaring count variable

int maxi=INT_MAX;

if(x.size()==y.size())
{

for(int i=0;i<x.size();i++)
{

if(x[i]!=y[i])

ct++;
}

maxi=ct;
}

else
{

if(x.size()>y.size())
{

string temp=x;

x=y;

y=temp;

}

for(int i=0;i<=(y.size()-x.size());i++)
{

ct=0;

for(int j=0;j<x.size();j++)
{

if(x[j]!=y[j+i])

++ct;
}

if(ct<maxi)

maxi=ct;
}
}

cout "maxi";
}

return 0;


}

This question is marked "community wiki".

64
accept rate: 0%

19.7k350498541

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,630
×2,575
×874
×640
×6
×5

question asked: 14 Jun '15, 13:30

question was seen: 1,566 times

last updated: 14 Jun '15, 23:14