由於ECNU OJ不能識別strlwr,所以還真是頭疼了一下:
‘strlwr’ was not declared in this scope
strcpy(a[i].s,strlwr(str));
使用transform(str.begin(), str.end(), s.begin(), ::tolower);將字串全部轉換成小寫:
string str;
string s;
transform(str.begin(), str.end(), s.begin(), ::tolower);
類似的,使用transform(str.begin(), str.end(), s.begin(), ::toupper);將字串全部轉換成大寫。
#include<bits/stdc++.h>
using namespace std;
struct N
{
string s;
} a[100010],b[100010];
int cmp(N x,N y)//結構體排序
{
return x.s>y.s;
}
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("F:/cb/read.txt","r",stdin);
//freopen("G:/x/out.txt","w",stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int t,ca=0;
cin>>t;
while(t--)
{
int n,m;
cin>>n;
for(int i=0; i<n; ++i)
{
string str;;
cin>>str;
transform(str.begin(), str.end(), str.begin(), ::tolower);
a[i].s=str;
//cout<<a[i].s<<endl;
}
cin>>m;
bool flag=true;
if(m!=n) flag=false;
else
{
for(int i=0; i<n; ++i)
{
string str;;
cin>>str;
transform(str.begin(), str.end(), str.begin(), ::tolower);
b[i].s=str;
//cout<<b[i].s<<endl;
}
sort(a,a+n,cmp);
sort(b,b+n,cmp);
for(int i=0; i<n; ++i)
{
if(a[i].s!=b[i].s)
{
flag=false;
break;
}
}
}
if(flag) cout<<"Case "<<++ca<<": YES"<<endl;
else cout<<"Case "<<++ca<<": NO"<<endl;
}
return 0;
}