9.17 网易互娱笔试ac统计
看看大佬们都a了几道
第一道
#include<bits/stdc++.h> using namespace std; int main(){ int t; cin >> t; while(t--){ int n; cin >> n; string a; while(n){ int tt = n%10; if(tt){ while(tt){ a += to_string(tt & 1); tt >>= 1; } }else{ a += "0"; } n /= 10; } //reverse(a.begin(), a.end()); int idx = 0; while(a[idx] == '0') idx++; string b = a.substr(idx); string c; //c.push_back(b[0]); char tmp = ' '; for(int i=0;i<b.size();i++){ if(b[i] == tmp) continue; c.push_back(b[i]); tmp = b[i]; } int res = 0; for(int i=0;i<c.size();i++){ res = res*10 + (c[i] - '0'); } //cout << a << endl; //cout << b << endl; cout << c << endl; } return 0; }第二道
#include<bits/stdc++.h> using namespace std; int main(){ int T; cin >> T; while(T--){ int n, m; cin >> n >> m; vector<int> h; for(int i=0;i<n;i++){ int tmp; cin >> tmp; h.push_back(tmp); } int idx, hx, minhx, res; minhx = h[m-1]; res = 0; int flag = 0; for(int idx = m;idx<n;idx++){ if(h[idx] < h[idx-1] && h[idx-1] > minhx){ res++; while(idx < n && h[idx] <= h[idx-1]){ minhx = h[idx]; idx++; } } } minhx = h[m-1]; for(int idx = m-2;idx>=0;idx--){ if(h[idx] < h[idx+1] && h[idx+1] > minhx){ res++; while(idx >=0 && h[idx] <= h[idx+1]){ minhx = h[idx]; idx--; } } } cout << res << endl;; } return 0; }