(C++字符串大小写转换)相似的句子

24. 相似的句子

Time limit per test: 2.0 seconds

Memory limit: 256 megabytes

有两个英文句子。如果把第一个句子中的单词进行某种排列,恰好得到第二个句子,那么就称这两个句子是相似的。(注意,单词比较是不区分大小写的。)例如:Today is Friday 和 friday toDAY Is 是相似的;it is a nice day 和 A nice day it is 是相似的;但 its beautiful isnt it 和it is Beautiful its isnt 不是相似的。

现在给出两个句子,判断他们是否相似。如果相似输出 YES,不相似输出 NO

Input

第一行一个整数 K,表示接下来有 K 组数据,1K5

接下来是 2K 行。每组数据有两行。每行以一个整数开头,表示这个句子的单词数量 n,然后是一个空格,紧接着有 n 个单词用一个空格隔开。输入保证单词中只出现大小写英文字母,且单词长度不超过 20

对于 20% 的数据,有 1n2

对于 40% 的数据,单词中只出现小写英文字母。

对于 60% 的数据,有 1n1000

对于 100% 的数据,有 1n105

Output

对于每组数据,输出 Case i: YES/NO。其中 i 为数据点编号(从 1 开始)。

Examples

input
4
3 Today is Friday
3 friday toDAY Is
5 it is a nice day
5 A nice day it is
4 its beautiful isnt it
5 it is Beautiful its isnt
3 its its its
3 sit its its
output
Case 1: YES
Case 2: YES
Case 3: NO
Case 4: NO

由于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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值