```C++ #include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); ll n; cin>>n; //A1 for(ll i = 1LL; i <= n; i++) cout<<i<<" "; cout<<"\n"; //A2 cout<<"1"; for(ll i = n; i > 1LL; i--) cout<<i<<" "; cout<<"\n"; //A3 for(ll i = n; i > 0LL; i--) cout<<i<<" "; return 0; } ``` B ```C++ #include <bits/stdc++.h> using namespace std; int main() { long long gt = 1, n; cin>>n; vector<long long> a(n); for(long long i = 1LL; i <= n; i++) a[i-1]=i; do{ for(long long i = 0LL; i < n; i++) cout<<a[i]; } while(next_permutation(a.begin(), e.end())); return 0; } ``` C ```C++ #include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; vector<int> a(n); for(int i = 0; i < n; i++) cin>>a[i]; set<int> s; for(int i : a) s.insert(i); for(int i : s) cout<<i<<" "; cout<<"\n"; //C2 for (int x : s) { cout << x <<" "; bool first = true; for (int i = 0; i < n; i++) { if (a[i] == x) { if (!first) cout << " "; cout << i; first = false; } } cout << "\n"; } //C3 map<int,int> fr; for (int x : a) fr[x]++; vector<int> dem(n+1, 0); for (const auto &p : fr) { int val = p.first, cnt = p.second; dem[cnt]++; } for (int k = 1; k <= n; k++) { cout << dem[k] << "\n"; } return 0; } ``` D ```C++ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n), prev(n), next(n); for (int i = 0; i < n; i++) cin >> a[i]; unordered_map<int,int> cuoi; for (int i = 0; i < n; i++) { if (cuoi.count(a[i])) prev[i] = cuoi[a[i]]; else prev[i] = -1; cuoi[a[i]] = i; } cuoi.clear(); for (int i = n-1; i >= 0; i--) { if (cuoi.count(a[i])) next[i] = cuoi[a[i]]; else next[i] = -1; cuoi[a[i]] = i; } for (int i = 0; i < n; i++) cout << prev[i] << " "; cout << "\n"; for (int i = 0; i < n; i++) cout << next[i] << " "; cout << "\n"; return 0; } ``` D2 ```C++ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<int> x(n); for (int i = 0; i < n; i++){ for (int k = 1; k <= n; k++){ if (a[i] == a[(i + k) % n]) { x[i] = k; break; } } } for (int i = 0; i < n; i++) cout << x[i] << " "; cout << "\n"; return 0; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up