Kolya is very absent-minded. Today his math teacher asked him to solve a simple problem with the equation 𝑎+1=𝑏 with positive integers 𝑎 and 𝑏, but Kolya forgot the numbers 𝑎 and 𝑏. He does, however, remember that the first (leftmost) digit of 𝑎 was 𝑑𝑎, and the first (leftmost) digit of 𝑏 was 𝑑𝑏.ios
Can you reconstruct any equation 𝑎+1=𝑏 that satisfies this property? It may be possible that Kolya misremembers the digits, and there is no suitable equation, in which case report so.git
The only line contains two space-separated digits 𝑑𝑎 and 𝑑𝑏 (1≤𝑑𝑎,𝑑𝑏≤9).ui
If there is no equation 𝑎+1=𝑏 with positive integers 𝑎 and 𝑏 such that the first digit of 𝑎 is 𝑑𝑎, and the first digit of 𝑏 is 𝑑𝑏, print a single number −1.this
Otherwise, print any suitable 𝑎 and 𝑏 that both are positive and do not exceed 109. It is guaranteed that if a solution exists, there also exists a solution with both numbers not exceeding 109.spa
input
1 2
output
199 200code
如今告诉你a+1=b,如今给你a和b的最高位,而后让你输出可能的a和b是什么,若是无解输出-1ci
可能性就3种,其余都无解,枚举这种可能性就好。rem
#include<iostream> using namespace std; int main(){ int a,b; cin>>a>>b; if(b==1&&a==9){ cout<<"9 10"<<endl; }else if(b-a==1){ cout<<a<<" "<<b<<endl; }else if(a==b){ cout<<a<<"1 "<<b<<"2"<<endl; }else{ cout<<"-1"<<endl; } }