Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

STONES Wrong Answer

$
0
0

My code looks correct. Its giving WA. Can someone help?

#include<iostream>
using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
              char a[110] = "", b[110] = "";
              int count1[200],count2[200];
              for(int i = 0;i < 150;i++) count1[i] = 0;
              for(int i = 0;i < 150;i++) count2[i] = 0;
              cin >> a >> b;
              for(int i = 0; a[i] != '\0';i++) count1[(int)a[i]]++;
              for(int i = 0; b[i] != '\0';i++) count2[(int)b[i]]++;
              int ans = 0;
              for(int i = 0; i < 150;i++)
                      if(count1[i] >= 1 && count2[i] >= 1) ans++;
              cout << ans << endl;
    }
    return 0;
}

The array count1[] keeps the track of the distinct characters in first string. count2[] keeps the track of 2nd. In the end we compare them. Can someone tell why it is giving WA?


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>