美团笔试1,2题,求告知其他题答案
第一题
#include<iostream>
using namespace std;
int main(){
int t;
cin>>t;
string name;
while(t--){
cin>>name;
if(name[0]>='A'&&name[0]<='Z'||name[0]>='a'&&name[0]<='z'){
}
else{
cout<<"Wrong"<<endl;
continue;
}
bool has_number=false;
bool is_hefa=true;
for(int i=1;i<name.size();i++){
if(name[i]>='0'&&name[i]<='9'){
has_number=true;
}
if(name[i]>='0'&&name[i]<='9'||name[i]>='A'&&name[i]<='Z'||name[i]>='a'&&name[i]<='z'){
}else{
is_hefa=false;
break;
}
}
if(has_number&&is_hefa){
cout<<"Accept"<<endl;
}else{
cout<<"Wrong"<<endl;
}
}
return 0;
}
第二题
using namespace std;
int main(){
int t;
cin>>t;
string name;
while(t--){
cin>>name;
if(name[0]>='A'&&name[0]<='Z'||name[0]>='a'&&name[0]<='z'){
}
else{
cout<<"Wrong"<<endl;
continue;
}
bool has_number=false;
bool is_hefa=true;
for(int i=1;i<name.size();i++){
if(name[i]>='0'&&name[i]<='9'){
has_number=true;
}
if(name[i]>='0'&&name[i]<='9'||name[i]>='A'&&name[i]<='Z'||name[i]>='a'&&name[i]<='z'){
}else{
is_hefa=false;
break;
}
}
if(has_number&&is_hefa){
cout<<"Accept"<<endl;
}else{
cout<<"Wrong"<<endl;
}
}
return 0;
}
第二题
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
int m,n;
cin>>m>>n;
vector<pair<int,int>> profit_index(m);
for(int i=1;i<=m;i++){
int v,w;
cin>>v>>w;
profit_index[i-1].first=v+2*w;
profit_index[i-1].second=i;
}
sort(profit_index.begin(),profit_index.end(),[](pair<int,int> &a,pair<int,int> &b){
if(a.first>b.first){
return true;
}
else if(a.first==b.first){
return a.second<b.second;
}else{
return false;
}
});
vector<int> ans;
for(int i=0;i<n;i++){
ans.push_back(profit_index[i].second);
}
sort(ans.begin(),ans.end());
for(auto data:ans ) cout<<data<<" ";
return 0;
}
求别的答案的地址
#include<algorithm>
#include<vector>
using namespace std;
int main(){
int m,n;
cin>>m>>n;
vector<pair<int,int>> profit_index(m);
for(int i=1;i<=m;i++){
int v,w;
cin>>v>>w;
profit_index[i-1].first=v+2*w;
profit_index[i-1].second=i;
}
sort(profit_index.begin(),profit_index.end(),[](pair<int,int> &a,pair<int,int> &b){
if(a.first>b.first){
return true;
}
else if(a.first==b.first){
return a.second<b.second;
}else{
return false;
}
});
vector<int> ans;
for(int i=0;i<n;i++){
ans.push_back(profit_index[i].second);
}
sort(ans.begin(),ans.end());
for(auto data:ans ) cout<<data<<" ";
return 0;
}
求别的答案的地址
全部评论
(0) 回帖