codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

748B.md (2060B)


      1 Source: https://codeforces.com/problemset/problem/748/B
      2 
      3 B. Santa Claus and Keyboard Check
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
     22 
     23 In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard.
     24 
     25 You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once.
     26 
     27 Input
     28 
     29 The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters.
     30 
     31 Output
     32 
     33 If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
     34 
     35 Otherwise, the first line of output should contain the only integer *k* (*k* ≥ 0) — the number of pairs of keys that should be swapped. The following *k* lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct.
     36 
     37 If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair.
     38 
     39 Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 helloworld  
     47 ehoolwlroz
     48 ```
     49 
     50 Output
     51 
     52 ```
     53 3  
     54 h e  
     55 l o  
     56 d z
     57 ```
     58 
     59 Input
     60 
     61 ```
     62 hastalavistababy  
     63 hastalavistababy
     64 ```
     65 
     66 Output
     67 
     68 ```
     69 0
     70 ```
     71 
     72 Input
     73 
     74 ```
     75 merrychristmas  
     76 christmasmerry
     77 ```
     78 
     79 Output
     80 
     81 ```
     82 -1
     83 ```