Its working fine with codeblocks using stdin and stdout, but when i am using freopen to redirect stream or running code in linux with "g++" , the input/output shows erratic behaviour !!! can anyone please tell me what might be the possible issue.
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,string> p;
int main()
{
// freopen("11.txt","r+",stdin);
// freopen("out.txt","w",stdout);
 int n,t,i,j,k;
string tmp;
cin>>t;
for(i=1;i<=t;i++)
{
    cin>>n;
    fflush(stdin);
priority_queue<p,vector<p>,less<p> > s;
    for(j=0;j<n;j++)
    { getline(cin,tmp);
        map<char,int> mp;
        int c=0;
        for(k=0;k<tmp.length();k++)
        {
            if(tmp[k]!=' '){
            if(mp.find(tmp[k])==mp.end())
            {c++;
              mp[tmp[k]]++;
            }
        }
        }
        if(!s.empty()&&s.top().first<c)
                { s.pop();}
                    s.push(make_pair(c,tmp));
    }
     p ans;
 if(!s.empty())
   ans =s.top();
   string qwe = ans.second;
  cout<<"Case #"<<i<<": "<<qwe<<endl;
  fflush(stdin);
}
return 0;
 }