http://www.codechef.com/problems/TECH04
#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
int t;
bool possible=true;
scanf("%d",&t,"\n");
for(int i=1; i<=t; i++){
char worda[30],wordb[30];
scanf("%s %s",worda,wordb,"\n");
string stringa,stringb;
stringa = worda; stringb = wordb;
for(int j=0; j<=(stringa.length()-1); j++){
char temp;
temp = stringa[j];
if (temp == '.') {continue;}
int counta = 1;
int countb = 0;
for (int k=j+1; k<=(stringa.length()-1); k++){
if (temp==stringa[k]) {counta++;
stringa[k]='.';}}
for (int k=0; k<=(stringb.length()-1); k++){
if (temp==stringb[k]) {countb++;}}
if (counta==countb) {possible = true;}
else {possible = false;
break;}
}
if (possible) {printf("YES\n");}
else {printf("NO\n");}
}
return 0;
}
This is my code for problem Anagram in Peer section. I’m getting Wrong answer. Please, tell me what’s wrong here since all my test cases go well, and there might be some big error because I’m pretty new in C++.
Thanks