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;
    } 
    
  • 相关阅读:
    浅谈c/c++中的指针问题
    谈谈八大排序算法问题
    隐藏在default construct后面的是什么
    浅谈编译过程和符号表重定位问题
    1.在VC编译器下面为什么每个头文件以及源文件都要包含“stdAfx.h”,那么stdAfx.h中到底存放了什么,用来做什么?
    成长从今天开始
    正则表达式
    安装RPM包或者安装源码包
    文档的压缩与打包
    文本编辑工具
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10781969.html
Copyright © 2011-2022 走看看