-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimKiem.cpp
47 lines (44 loc) · 891 Bytes
/
TimKiem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
using namespace std;
void inputArray(int arr[100][2], int n)
{
for (int i = 0; i < n; i++)
for (int j = 0; j < 2; j++)
cin >> arr[i][j];
}
void splitNum(int n, int checkNum)
{
int a = 0;
int dem = 1;
int arr[100];
int vitri = 0;
bool check = false;
while (n > 0)
{
a = n % 10;
n /= 10;
arr[dem] = a;
dem++;
}
for (int i = dem; i > 0; i--)
if (arr[i] == checkNum)
{
vitri = i;
check = true;
break;
}
if (check == 1)
cout << dem - vitri << endl;
else
cout << "-1" << endl;
}
int main()
{
int n;
cin >> n;
int arr[100][2];
inputArray(arr, n);
for (int i = 0; i < n; i++)
splitNum(arr[i][0], arr[i][1]);
return 0;
}