Computer Science, asked by ttagore159, 8 months ago

Faulty Keyboard Problem Description Mr. Wick has a faulty keyboard. Some of the keys of the keyboard don't work. So he has copied all those characters corresponding to the faulty keys on a clipboard. Whenever those characters need to be typed he pastes it from the clipboard. In typing whatever is required he needs to make use of paste, backspace and cursor traversal operations. Help him in minimize the number of operations he needs to do to complete his typing assignment. Each operation has one unit weightage. Constraints 1 <= S <= 16 1 <= T<= 10^4 String T and S will only be comprised of letters a-z and digits 0-9 Input First line contains text T to be typed Second line contains string S of all the faulty keys pasted on clipboard Output Print the minimum number of operations required for typing the text T Time Limit 1 Examples Example 1 Input experience was ultimate ew Output 14 Explanation experience =(2+2+2+2) =[ {p+b} + {p+b} +{p+b} +{p+b} ] was=(4)=[ p+m+b+m] ultimate=(2)=[ p+b ] where p=paste, b=backspace ,m= move cursor Example 2 Input supreme court is the highest judicial court su Output 17 Explanation supreme =(1) =[ p] court=(4)=[ p+m+b+m] is=(2)=[ p+b ] the=(0) highest=(2)=[p+b] judicial=(4)=[p+m+b+m] court=(4)=[p+m+b+m]

Answers

Answered by heavenlydemonrvk
2

Answer:

Explanation:

Mr. Wick has a faulty keyboard. Some of the keys of the keyboard don't work.

Answered by dreamrob
0

1 <= T <= 10^4

1 <= S <= 16

String T and S will only be comprised of letters a-z and digits 0-9

  • Input

First line contains text T to be typed

Second line contains string S of all the faulty keys pasted on clipboard

  • Output

Print the minimum number of operations required for typing the text T

  • Time Limit

1

  • Explained:

experience =(2+2+2+2) =[ {p+b} + {p+b}+{p+b}+{p+b} ]

was=(4)=[p+m+b+m]

ultimate=(2)=[p+b]

where p-paste, b-backspace,m= move

cursor

#include <iostream>

#include<bits/stdc++.h>

using namespace std;

  • Source Code

int main()

{

   string t,s;

 

   cin>>t;

 

   cin>>s;

   unordered_set<char>st;

   for(int i=0;i<int(s.length());i++){

       st.insert(s[i]);

   }

   long long sum=0;

   long long i;

   for(i=0;i<(long long)t.length();){

       if(st.find(t[i])!=st.end()){

           int f=0,j=0;

           while(j<int(s.length())){

               if(s[j]==t[i]){

                   j++;

                   i++;

                   f+=1;

               }

               else if(s[j]!=t[i] && f==0){

                   j++;

               }

               else{

                   break;

               }

            }

            if(f==j){

                sum+=(1+s.length()-f);

            }

            else {

                sum+=(1+s.length()+f);

            }

       }

       else{

           i++;

       }

   }

   cout <<sum<<endl;

   return 0;

}

#SPJ3

Similar questions