算法入门-构造算法BGN72 茉茉的密码12345678910111213141516171819202122232425262728293031//茉茉的密码#include <bits/stdc++.h>using namespace std;typedef long long ll;const int INF = 0x3f3f3f3f;#define sz size()int main () { ios_base::sync_with_stdio (false); cin.tie (0); map<char,ll> m; int n; cin >> n; vector<string> v(n); for (int i=0;i<n;i++) cin >> v[i]; for (int i=0;i<n;i++) { map<char,ll> mo; for (int j=0;j<v[i].sz;j++) { if(!mo[v[i][j]]){ mo[v[i][j]]++; m[v[i][j]]++; } } } for (const auto s: m) { if (s.second ==n) { cout << s.first; return 0; } }} BGN73123456789101112#include <iostream>using namespace std;int main() { int x; cin>>x; if(x==1){ cout<<-1; return 0; } cout<<x<<' '<<x;} BGN74123456789101112131415161718192021222324252627282930313233#include <bits/stdc++.h>using namespace std;#define pb push_back#define sz size()#define vll vector<long long>using ll=long long;using ull = unsigned long long;const int MOD1=1e9+7;const int MOD2=998244353;void solve() { ll n,k; cin>>n>>k; vector<vector<int>> v(n,vector<int>(n,0)); for (int i=0;i<n;i++) { v[i][i]=k; } for (int i=0;i<n;i++) { for (int j=0;j<n;j++) { cout<<v[i][j]<<" "; } cout<<'\n'; }}int main() { ios::sync_with_stdio(0); cin.tie(nullptr); int t=1; //cin>>t; while (t--) { solve(); }} BGN7612345678910111213141516171819202122232425262728293031323334//// Created by XIAOBAI on 2026/6/2.//#include <bits/stdc++.h>using namespace std;const int MOD1 = 1e9 + 7;const int MOD2 = 998244353;using ll = long long;using ull = unsigned long long;bool cmp(int a,int b) { return a>b;}ll get(ll x) { if (x==0) return 0; if (x==1) return 1; return get(x/2)+get(x%2);}void solve() { ll n; cin>>n; cout<<get(n);}int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T=1; cin>>T; while(T--) { solve(); }}