Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <unordered_set>
- using namespace std;
- bool exista(int x, int v[], int k)
- {
- for(int i = 1; i <= k; i++)
- if(v[i] == x)
- return true;
- return false;
- }
- // k este numarul de elemente din v
- void gaseste_aproape(int n, int v[], int &k)
- {
- int put = 1, c, x;
- while(put < n)
- {
- c = (n / put) % 10;
- if(c < 9)
- {
- x = n + put;
- if(exista(x, v, k) == false)
- v[++k] = x;
- }
- if(c > 1 || (c == 1 && n > put*10))
- {
- x = n - put;
- if(exista(x, v, k) == false)
- v[++k] = x;
- }
- put *= 10;
- }
- }
- int main()
- {
- ifstream in("aproape.in");
- ofstream out("aproape.out");
- int n, c;
- in >> c >> n;
- int v[1000], k = 0;
- int v2[1000], k2 = 0;
- if(c == 1)
- {
- if(n == 0)
- out << 1;
- else
- {
- int cnt = 0;
- do
- {
- n = n / 10;
- cnt++;
- }
- while(n > 0);
- out << cnt;
- }
- }
- else if(c == 2)
- {
- gaseste_aproape(n, v, k);
- out << k;
- }
- else
- {
- gaseste_aproape(n, v, k);
- for(int i = 1; i <= k; i++)
- gaseste_aproape(v[i], v2, k2);
- out << k2;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement