#include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ int n,m; while(scanf("%d %d",&n,&m)!=EOF){ int *score = (int*)malloc(sizeof(int)*n); int res[5000]; int cnt = 0; for(int i=0; i<n; i++) scanf("%d",&score[i]); char t; int a=0,b=0; while(m--){ scanf("%c",&t); if(t == '/n') scanf("%c",&t); scanf("%d %d",&a,&b); if(t == 'Q'){ int max = 0; for(int i=a;i<=b;i++){ if(score[i] > max) max = score[i]; } res[cnt++] = max; }else score[a] = b; } for(int i=0; i<cnt; i++) printf("%d/n",res[i]); free(score); } return 0; }
#include <iostream> #include <string> #include <vector> using namespace std; struct Log{ string path; int row; int count; }; static vector<Log> vec; void writeLog(Log &lg){ for(int i=0;i<vec.size();i++){ if(vec[i].path == lg.path && vec[i].row == lg.row){ Log tmp = vec[i]; vec.erase(vec.begin()+i); tmp.count ++; vec.push_back(tmp); return ; } } lg.count = 1; vec.push_back(lg); if(vec.size() > 8) vec.erase(vec.begin()); } void doLog(){ for(int i=0; i<vec.size(); i++){ Log lg = vec[i]; int len = lg.path.size(),cnt = 0; for(int i=len-1; i>=0 && cnt<16; i--){ if(lg.path[i] == '//') break; else{ cnt ++; } } lg.path = lg.path.substr(len-cnt,cnt); vec[i] = lg; } } int main(){ Log lg; while(cin>>lg.path>>lg.row){ lg.path = "E://hello"; lg.row = 45; writeLog(lg); } doLog(); for(int i=0; i<vec.size(); i++) cout<<vec[i].path<<" "<<vec[i].row<<" "<<vec[i].count<<endl; return 0; }
#include <iostream> #include <string> #include <vector> using namespace std; //个子 对子 顺子 三个 四个 对王 static int judgeType(vector<char> &vec,int *value){ if(vec.size()==2){ if(vec[0]=='r' || vec[0]=='R') return 6; else{ *value=vec[0]; return 2; } } *value=vec[0]; return vec.size(); } static void print(vector<char> &vec){ if(vec[0] == 'r') cout<<"joker"; else if(vec[0] == 'R') cout<<"JOKER"; else if(vec[0] == 'T') cout<<"10"; else cout<<vec[0]; for(int i=1; i<vec.size(); i++){ if(vec[i] == 'r') cout<<" joker"; else if(vec[i] == 'R') cout<<" JOKER"; else if(vec[i] == 'T') cout<<" 10"; else cout<<" "<<vec[i]; } cout<<endl; } bool comp(char a,char b){ switch(a){ case 'T': a = 'a';break; case 'J': a = 'b';break; case 'Q': a = 'c';break; case 'K': a = 'd';break; case 'A': a = 'e';break; case 'r': a = 'f';break; case 'R': a = 'g';break; } switch(b){ case 'T': b = 'a';break; case 'J': b = 'b';break; case 'Q': b = 'c';break; case 'K': b = 'd';break; case 'A': b = 'e';break; case 'r': b = 'f';break; case 'R': b = 'g';break; } return a>b; } int main(){ string str; while(getline(cin,str)){ int len = str.size(); vector<char> vec1,vec2; bool flag = false; for(int i=0; i<len; i++){ if(str[i] == '-'){ flag = 1; continue; } else if(isspace(str[i])) continue; if(flag){ if(str[i]=='j') {vec1.push_back('r');i=i+4;} else if(str[i]=='J' && i==len-1){vec1.push_back('J');} else if(str[i]=='J' && str[i+1]=='O'){vec1.push_back('R');i=i+4;} else if(str[i]=='1') {vec1.push_back('T');i=i+1;} else vec1.push_back(str[i]); }else{ if(str[i]=='j') {vec2.push_back('r');i=i+4;} else if(str[i]=='J' && i==len-1){vec2.push_back('J');} else if(str[i]=='J' && str[i+1]=='O'){vec2.push_back('R');i=i+4;} else if(str[i]=='1') {vec2.push_back('T');i=i+1;} else vec2.push_back(str[i]); } } int value1 = 0,value2 = 0; int type1 = judgeType(vec1,&value1); int type2 = judgeType(vec2,&value2); if(type1 == type2){ if(comp(value1,value2)) print(vec1); else print(vec2); }else{ if((type1==4 || type1==6) && type2<6) print(vec1); else if((type2==4 || type2==6) && type1<6) print(vec2); else cout<<"ERROR"<<endl; } } return 0; }
华为上机题,对算法本身要求并不高,关键是要注意细节。华为OJ平台感觉做的很不好,直接显示错误或正确,一点错误提示都没有。最坑的就是每题只有5次提交机会,搞的大家都不敢轻易提交了。