can u please tell me what is wrong with this code it is giving right output. But wrong answer when ever i submit it.

//code of chef and codes
//http://www.codechef.com/problems/CHODE

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
void sort( long int arr[26][4]) 
{  int j,temp1,temp2;
	for(int i=0;i<26;i++)
	{
	j=i;
    temp1=arr[j+1][0];
    temp2=arr[j+1][1];
    while(j>=0 && arr[j][1]>temp2)
    {
		 arr[j+1][0]=arr[j][0];
	 	 arr[j+1][1]=arr[j][1];
        	     j--;
   }
    arr[j+1][0]=temp1;
    arr[j+1][1]=temp2;
	}
}
int main()
{
int t;char ch;
scanf("%d",&t);
	while(t>0)
	{
        long int map[26][4]={0,0,0,0};
        char arr[28]={'\0'},arr1[100000]={'\0'},arr2[100000]={'\0'};
        for(int i=0;i<26;i++)
	{
	map[i][0]=i;
	map[i][2]=i;
        map[i][1]=0;
        map[i][3]=0;        
        }
        scanf("%s",arr);
        cin.get(ch);
        cin.getline(arr1,100000);
        int i=0;
	for(i=0;arr1[i]!='\0';i++)
	 {
	   if(arr1[i]>='a' && arr1[i]<='z')
		 map[int(arr1[i]-'a')][1]++;
           else if(arr1[i]>='A' && arr1[i]<='Z')
                 map[int(arr1[i]-'A')][1]++;
         }
        sort(map);
  for(int i=0;i<26;i++)
  {
  for(int j=0;j<26;j++)
  {
	  if(map[j][0]==i)
	  {
       	  map[i][3]=map[j][2];
	  break;
	  }
  }
  }
 for(i=0;arr1[i]!='\0';i++)
   {
 if(arr1[i]>='a' && arr1[i]<='z')
  arr2[i]=arr[map[map[int(arr1[i])-97][3]][2]];
 else if(arr1[i]>='A' && arr1[i]<='Z')
  arr2[i]=(arr[map[map[int(arr1[i])-65][3]][2]]-32);
 else
  arr2[i]=arr1[i];
   }
 arr2[i]='\0';
printf("%s",arr2);
 t--;
}
}

Look dude, the statement where u are printing your answer, you should print your answer and then a new line character “\n”.

So change this - printf("%s",arr2);
by this - printf("%s\n",arr2);

and all done.
Just a little mistake…

6 Likes

still wrong answer

plz tell me whats wrong in this i m getting frustrated … whats wrong in this

http://www.codechef.com/viewsolution/3106933

Look at this and it is accepted after adding ‘\n’ in the printf statement…

I looked into these new solution of yours, you edited them a little bit but no ‘\n’ in the printf, this is causing you a WA.

2 Likes

Your solution gets AC in c++(gcc-4.3.2) but a WA in c++(gcc-4.8.1) and c++11(gcc-4.8.1)…
So do submit in c++(gcc-4.3.2) after adding ‘\n’ in printf()

3 Likes

thanks brother… :slight_smile: