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;
    } 
    
  • 相关阅读:
    【linux】Centos下登陆mysql报错#1045
    tomcat在centos7里面启动很慢的解决办法
    tomcat日志文件 转载https://www.cnblogs.com/operationhome/p/9680040.html
    tomcat的文件目录结构
    centos 7服务器下tomcat 问题 1.配置问题
    x11转发遇到的问题
    x11转发,可以在shell里面看到图形界面
    linux里面tomcat配置遇到的问题
    vim中文乱码 vim字符集设置
    c#.net常见字符串处理方法
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10781969.html
Copyright © 2011-2022 走看看