I am facing a runtime issue in my code.Can anyone help me with my code: My code link: https://pastebin.com/qCC4GsPS. Just check the merge and mergesort function in this link.
| № | Пользователь | Рейтинг |
|---|---|---|
| 1 | jiangly | 3810 |
| 2 | Benq | 3676 |
| 3 | Kevin114514 | 3655 |
| 4 | maroonrk | 3463 |
| 5 | strapple | 3447 |
| 6 | Um_nik | 3387 |
| 7 | heuristica | 3322 |
| 8 | turmax | 3317 |
| 9 | tourist | 3307 |
| 10 | jiangbowen | 3291 |
| Страны | Города | Организации | Всё → |
| № | Пользователь | Вклад |
|---|---|---|
| 1 | Qingyu | 156 |
| 2 | nik_exists | 150 |
| 2 | maspy | 150 |
| 4 | Um_nik | 141 |
| 5 | Errichto | 139 |
| 6 | adamant | 137 |
| 7 | AmShZ | 136 |
| 8 | BledDest | 132 |
| 9 | maroonrk | 131 |
| 10 | qwexd | 129 |
I am facing a runtime issue in my code.Can anyone help me with my code: My code link: https://pastebin.com/qCC4GsPS. Just check the merge and mergesort function in this link.
How to approach this question when 0 is also included in the digit set. My solution is giving the wrong answer for this.
problem link; https://leetcode.com/problems/numbers-at-most-n-given-digit-set/
#include<bits/stdc++.h> #include <vector> #include <algorithm> using namespace std;
#define ll long long int
ll s1(vector &v, ll N) {
ll i, j, n = v.size(), ans = 0; string ss = "", s = "";
for (i = 0; i < n; i++) { s += v[i]; } ss = to_string(N);
ll d = ss.length(), f = 0;
// for numbers with atmost (d-1) digits we have n choices for each position
for (i = 1; i < d; i++)
{
if (i == 1)
{
ans += pow(n — 1, i);
continue;
}
ans += pow(n, i);
}
ll z = 0;
for (j = 0; j < d; j++)
{
f = 0; //to check whether that particular digit of N exists in the given string or not
for (i = 0; i < s.length(); i++)
{
if (z == 0)
{
z++;
continue;
}
//if a digit less than the current digit is encountered, we have 'n' possibilites for each digit to the right of 'i'
if (s[i] < ss[j])
{
ans += pow(n, d - (j + 1));
z++;
}
else if (s[i] == ss[j])
{
z++;
f = 1;
break;
}
}
if (!f)
{
break;
} //if we do not have jth digit in 's' , no need to continue
}
ans += f;
return and;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll l, r;
ll k, i, g;
cin >> l ;
vector<ll> v1;
ll x = 0;
while (x <= 9)
{
v1.push_back(x);
x = x + k;
}
vector<string> s;
for (i = 0; i < v1.size(); i++)
{
g = v1[i];
char c = g + '0';
string d(1, c);
s.push_back(d);
// cout << D[i] << " ";
}
cout << s1(l) << '\n';
}
}| Название |
|---|


