http://blog.csdn.net/hcu5555/article/details/20555229给出了专门取代gets()的代码,亲测有用!!
举例如下:(别问我哪里来的代码)
如果之前有人提到过或者使用有问题,欢迎指正
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;
#define U_MAX 2000
char *get_str(char *str)
{
fgets(str,U_MAX,stdin);
if(str[strlen(str)-1] == '\n')
str[strlen(str)-1] = '\0';
return str;
}
inline int read()
{
int X=0,w=1; char ch=0;
while(ch<'0' || ch>'9') {if(ch=='-') w=-1;ch=getchar();}
while(ch>='0' && ch<='9') X=(X<<3)+(X<<1)+ch-'0',ch=getchar();
return X*w;
}
int T,s1,t1;
char s[2005];
char t[2005];
int loc[30];
bool jud(char c){return (c>='a'&&c<='z')?(true):(false);}
int main()
{
freopen("copycat.in","r",stdin);
freopen("copycat.out","w",stdout);
T=read();
while(T--)
{
int i=0,ans=0,cnt=1;
memset(loc,0,sizeof(loc));
get_str(s);s1=strlen(s);
get_str(t);t1=strlen(t);
if(s1==t1)
for(i=0;i<s1;i++)
{
if(!jud(s[i]))
{
if(!jud(t[i]))
{
if(s[i]!=t[i]){cnt=0;break;}
}
else {cnt=0;break;}
}
if(jud(s[i])&&jud(t[i]))
{
if(!loc[s[i]-'a'+1])loc[s[i]-'a'+1]=t[i]-'a'+1;
else if(loc[s[i]-'a'+1]!=t[i]-'a'+1){cnt=0;break;}
}
}
else cnt=0;
if(i==s1&&cnt)ans=1;
cout << ans << endl;
}
return 0;
}