好未来笔试
//第三题 其实还可以更简单 #include<bits/stdc++.h> using namespace std; void rotate1(vector<int>& nums,int k) { int len = nums.size(); if(k!=0) { k = k>=len?k%len:k; vector<int> temp; if(k!=0) { reverse(nums.begin(), nums.end()); reverse(nums.begin(), nums.begin()+k); reverse(nums.begin()+k, nums.end()); } } } int main() { string str; cin>>str; stringstream ss(str); int k; cin>>k; vector<int> nums; while(getline(ss,str,',')) { nums.push_back(stoi(str)); } rotate1(nums,k); for(int i=0;i<nums.size();i++) { cout<<nums[i]; if(i!=nums.size()-1) cout<<","; } return 0; } //第二题 #include<bits/stdc++.h> using namespace std; vector<vector<int>> fun(vector<int>& nums) { vector<vector<int>> ret; int n = nums.size(); sort(nums.begin(), nums.end()); set<vector<int>> all; for(int i=0;i<nums.size()-2;i++) { if(nums[i]>0) break; else if(i>0&&nums[i]==nums[i-1]) continue; int target = -nums[i]; int j=i+1; int k = nums.size()-1; while(j<k) { if(nums[j]+nums[k]==target) { while(nums[k]==nums[k-1]&&j<k) { k--; } while(nums[j]==nums[j+1]&&j<k) ++j; ret.push_back({nums[i],nums[j],nums[k]}); k--; j++; } else if(nums[j]+nums[k]>target) k--; else if(nums[j]+nums[k]<target) j++; } } return ret; } int main() { vector<int> nums; int n; while(1) { cin>>n; nums.push_back(n); if(cin.get()=='\n') break; } vector<vector<int>> ret = fun(nums); for(int i=0;i<ret.size();i++) { for(int j=0;j<ret[0].size();j++) { cout<<ret[i][j]<<" "; } cout<<endl; } return 0; } //第一题 #include<bits/stdc++.h> using namespace std; int main() { string version1,version2; cin>>version1>>version2; stringstream ss1(version1); stringstream ss2(version2); while (1) { /* code */ string str1,str2; getline(ss1,str1,'.'); int v1 = stoi(str1); getline(ss2,str2,'.'); if(str2==""||str1=="") { if(str2==""&&str1!=""&&stol(str1)!=0) cout<<1<<endl; else if(str1==""&&str2!=""&&stol(str2)!=0) cout<<-1<<endl; else cout<<0<<endl; return 0; } int v2 =stoi(str2); if(v1<v2) { cout<<-1<<endl; return 0; } if(v1>v2) { cout<<1<<endl; return 0; } } return 0; }
#好未来笔试讨论##笔经##好未来#