zoukankan      html  css  js  c++  java
  • 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;
    } 
    
  • 相关阅读:
    css(完)
    HTML学习(完)
    leetcode学习03
    多线程详解2(完)
    windows7 64位下安装apache和php
    一个js,记录方便查询。
    用了锚的时候,有的层被覆盖了。
    日,在ie10下面hover里不能控制table
    在实现tab的时候,margin-bottom:-1px无效的问题
    javascript中,在一个类里attache的event事件中,如果调用类的成员变量和方法
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10781969.html
Copyright © 2011-2022 走看看