HDU 4357 String change

http://acm.hdu.edu.cn/showproblem.php?pid=4357

题意:

给定a串b串,问能否把a变成b串

方法:任选a的2个字母,ascil+=1 然后交换位置,可以操作任意多次。

3个及3个以上一定可以T^T

2个就暴力判一下

像这种只要最后结果不求过程的题目,往往都是有规律可循的


#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
using namespace std;

char a[100];
char b[100];

int check(){

    int cnt = 30;
    while(cnt--){
        if(a[0]==b[0]  && a[1] == b[1]) return 1;
        a[0] = (a[0]-'a'+1)%26 + 'a';
        a[1] = (a[1]-'a'+1)%26 + 'a';
        char c = a[0];
        a[0] = a[1];
        a[1] = c;

    }
    return 0;

}
int main()
{
    int i,j,k,t,m,n;

    cin>>t;
    int cnt = 1;
    while(t--){
        cin>>a;
        cin>>b;
        printf("Case #%d: ",cnt++);
        int len = strlen(a);

        
        if(len==2){
            if( check()) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else{
            int sum = 0;
            for(i=0;i<len;i++){
                sum+=(a[i]-'a');
            }
            for(i=0;i<len;i++){
                sum+=(b[i]-'a');
            }

            if( sum % 2 ==0 ){
                cout<<"YES"<<endl;
            }
            else
                cout<<"NO"<<endl;
        }
        
       // cout<<endl;
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值