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.
# | User | Rating |
---|---|---|
1 | tourist | 3690 |
2 | jiangly | 3647 |
3 | Benq | 3581 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | Radewoosh | 3509 |
8 | ecnerwala | 3486 |
9 | jqdai0815 | 3474 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 165 |
3 | adamant | 161 |
4 | TheScrasse | 160 |
5 | nor | 158 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 152 |
8 | orz | 146 |
9 | SecondThread | 145 |
9 | pajenegod | 145 |
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'; } }
Name |
---|