• CodeForces


    Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.

    Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not.

    Input

    The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.

    The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.

    The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length.

    Output

    Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".

    Examples

    Input

    ab
    ba
    

    Output

    YES
    

    Input

    aa
    ab
    

    Output

    NO
    

    Note

    • First example: you can simply swap two letters in string "ab". So we get "ba".
    • Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".

    题解:题目大意是让你判断是否能通过换两个字母的位置是否一样

    代码:

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    
    using namespace std;
    
    int main()
    {
        char s1[100005],s2[100005];
       scanf("%s%s",s1,s2);
    	int flag=0;
    	int a[100005];
    	int temp=0;
    	for(int t=0;t<strlen(s1);t++)
    	{
    		
    		if(strlen(s1)!=strlen(s2))
    		{
    			flag=3;
    		}
    	    if(s1[t]!=s2[t])
    		{
    	       a[temp]=t;
    	       temp++;
    		flag++;
    		if(flag==3)
    		break;
    	    }
    	    else
    	    continue;
    	}	
    	if(flag==2)
    	{
    		if(s1[a[0]]==s2[a[1]]&&s1[a[1]]==s2[a[0]])
    		{
    			printf("YES
    ");
    		}
    		else
    		{
    			printf("NO
    ");
    		}
    	}
    	else
    	{
    		printf("NO
    ");
    	}
    	
    	return 0;
    } 
    
  • 相关阅读:
    接口 多态
    继承extends (特点、重写、覆盖、应用)抽象abstract(定义、特点、细节)
    0515 面向对象 类与对象、局部、成员变量、基本、引用类型、封装 private 和this 及应用
    Eclipse 快捷键
    Flutter Framework启动代码阅读
    Flutter Widget概览
    Flutter局部状态管理
    iconfont应用
    implicit_animations.dart阅读
    Flutter异常搜集方案
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10781970.html
Copyright © 2020-2023  润新知