• API
• FAQ
• Tools
• Archive
daily pastebin goal
16%
SHARE
TWEET

# Untitled

a guest Jan 20th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. #include <vector>
3. #include <stdlib.h>
4. using namespace std;
5.
6.
7.
8. vector<int> strToVector(const string& s) {
12.     int sign = 1;
13.     int num = 0;
14.     int degree;
15.     bool is_first = 1;
16.     vector<int> coef(20);
17.     for (const char& c: s) {
18.         if (reading_num == 1 && isdigit(c)) {
19.             num = num*10 + c - '0';
20.         }
21.
22.         if (reading_degree && isdigit(c)) {
23.             degree = degree*10 + c - '0';
24.         }
25.
26.         if (reading_sign == 1) {
27.             if (c == '+') {
28.                 num = max(1, num);
29.                 degree = max(1, degree);
30.                 coef[degree] = sign*num;
31.                 num = 0;
32.                 sign = 1;
34.                 degree = 0;
36.             } else if (c == '-') {
37.                 num = max(1, num);
38.                 degree = max(1, degree);
39.                 coef[degree] = sign*num;
40.                 num = 0;
41.                 sign = -1;
43.                 degree = 0;
45.             }
46.         }
47.
48.         if (c == 'x') {
49.
52.             degree = 0;
55.         }
56.
57.
58.     }
59.     num = max(1, num);
60.     coef[degree] = sign*num;
61.     return coef;
62. }
63.
64. int main() {
65.     string s;
66.     cin >> s;
67.     vector<int> vec = strToVector(s);
68.     for (int i = 0; i < vec.size(); ++i) {
69.         if (vec[i]) {
70.             cout << i << " - " << vec[i] << endl;
71.         }
72.     }
73.     return 0;
74. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top