URI Online Judge | 1241
Fit or Dont Fit II
By Neilor Tonin, URI
Brazil
Timelimit: 1
Brazil
Paulinho have again in your hands another problem. Now the teacher asked him to make a new program to verify from two big numbers A and B, if B corresponds to the last digit of A.
Input
The input consists of several test cases. The first line of input contains an integer N that indicates the number of test cases. Each test case consists of two numbers A and B greather than zero, with up to 1000 digits each.
Output
For each test case, print a message informing if the second number fit ("encaixa" in portughese) or didn't fit ("nao encaixa") in the first number.
| Sample Input | Sample Output |
| 4 56234523485723854755454545478690 78690 5434554 543 1243 1243 54 64545454545454545454545454545454554 | encaixa nao encaixa encaixa nao encaixa |
URI 1241 Fit Or Don't Fit | Solution in C++
#include <cstdio>#include <iostream>#include <vector>#include <string>using namespace std;int main(){ int n, sizeA, sizeB, tmp; string a, b; bool check; scanf("%i", &n); for (int i = 0; i < n; ++i) { check = true; cin >> a >> b; sizeA = a.length(); sizeB = b.length(); char arrayA[sizeA + 1]; char arrayB[sizeB + 1]; if(sizeA < sizeB){ puts("nao encaixa"); continue; } for (int i = 0; i < sizeA; ++i) arrayA[i] = a.at(i); for (int i = 0; i < sizeB; ++i) arrayB[i] = b.at(i); tmp = sizeA - sizeB; for (int i = 0; tmp < sizeA; ++tmp, ++i) { if(arrayA[tmp] != arrayB[i]){ check = false; break; } } if(check == true){ puts("encaixa"); }else{ puts("nao encaixa"); } } return 0;}
No comments:
Write commentsTo know more about the problem, give us your valuable commment. We'll try to help you. Thanks