-4
#include <iostream>
#include <cstring> 
using namespace std;

int main() {
    std::string a, b;
    int number_cases=0,i,j,count=0;
    cin>>number_cases;
    while(number_cases!=0)
        {
            cin>>a;
            cin>>b;
            for(i=0;i<a.size();i++) {
                for(j=0;j<b.size();j++) {
                    if(a[i]==b[j]); {
                        count++;
                        b[j]='#';
                        break;
                    }
                }
            }
            cout<<count<<endl;
            count=0;
            --number_cases;
        }
}

http://www.codechef.com/FEB14/problems/LCPESY I am getting TLE error on submiting , suggest some ways to optimise output.

  • 1
    Please do not remove errors from your code, if they are discussed in the answers below. This makes it harder for other people to learn from your mistakes. – Markus Mayr Feb 11 '14 at 06:43
  • This question appears to be off-topic because it is lacking the minimal understanding. – László Papp Feb 16 '14 at 00:55

2 Answers2

2

The only mistake is

if(a[i]==b[j]);

Remove ";" from if statement

if(a[i]==b[j])

It'll work fine

G one
  • 2,679
  • 2
  • 14
  • 18
0
#include <iostream>
#include <cstring> 
using namespace std;

int main() {
    std::string a, b;

Since you write using namespace std the "std::" is not nessecary.

But the reason your program doesn't work is since you have a ";" in your if statement.

if(a[i]==b[j]);

Should be

if(a[i]==b[j]) 
Jasin Ali
  • 66
  • 3