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;
    } 
    
  • 相关阅读:
    MIPI CSI2学习(一):说一说MIPI CSI2
    图解数据结构树之AVL树
    查找树ADT--二叉查找树
    hisi mmz模块驱动讲解
    抓包工具 tcpdump 用法说明
    4. 海思Hi3519A MPP从入门到精通(四 视频输出)
    PHP无限分类分类导航LINK的代码实现
    PHP 无限极分类下拉列表实现
    PHP无限极分类原理
    微信支付回调验证签名处理
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10781970.html
Copyright © 2011-2022 走看看