为什么会提示 没有循环处理case
全部评论
#include<cstdio> #include<iostream> #include<string> using namespace std; int str_match(int a,int b){ //int match=0; string t; string p; t = to_string(a); p = to_string(b); if(t.find(p)==t.npos) return 0; else //cout<<" ["<<t.find(p)<<"] "; return 1; //cout<<t.length()<<p.length(); //int lent = t.length(); //int lenp = p.length(); //int k=0,l=0; //while(k<lent && l<lenp){ // if(l==-1 or t[k]==p[l]){ // k++; // l++; // }else{ // k=k-l+1; // l=0; // } // if(l==lenp){ // return k-l; // }else{ // return -1; // } //} //char(t); //char(p); //if(strchr(t,p)) // match=1; //return match; } int main(){ //输入 I<>、R_ori<> int i,j,I_sum,R_ori_sum; cin>>I_sum; //cout<<I_sum<<" "; int I[I_sum]; for(i=0;i<I_sum;i++){ cin>>I[i]; //cout<<I[i]<<" "; } cin>>R_ori_sum; //cout<<R_ori_sum<<" "; int R_ori[R_ori_sum]; for(i=0;i<R_ori_sum;i++){ cin>>R_ori[i]; //cout<<R_ori[i]<<" "; } //删除R_ori<>中重复的元素,并从小到大地排序,保存在R<>中 int R_sum=R_ori_sum; int sum_flag=0; //////“删除”R_ori<>中重复的元素 for(i=0;i<R_ori_sum;i++){ sum_flag += R_ori[i]; } sum_flag++;//770 //cout<<sum_flag<<"!!"; for(i=0;i<R_ori_sum;i++){ for(j=i+1;j<R_ori_sum;j++){ if(R_ori[i]==R_ori[j] and R_ori[i]!=sum_flag){ R_ori[j]=sum_flag; R_sum--; } } } //cout<<R_sum<<"??"; 10 int R[R_sum]; j=0; for(i=0;i<R_sum;i++){ while(R_ori[j]==sum_flag) j++; R[i]=R_ori[j]; j++; } //////R<>排序 int temp; for(i=0;i<R_sum;i++){ for(j=i;j<R_sum;j++){ if(R[i]>R[j]){ temp = R[i]; R[i] = R[j]; R[j]= temp; } } }//冒泡 //for(i=0;i<R_sum;i++){ // cout<<R[i]<<"ON"<<" "; //} /////////////////////////////////////////////////////////////////// //判断字符串匹配 int I_match_flag,I_location_flag; for(i=0;i<I_sum;i++){ I_match_flag += I[i]; I_location_flag += i; } I_match_flag++; I_location_flag++; //cout<<I_sum<<" "<<I_match_flag<<" "<<I_location_flag<<"]] "; // 24 140019 277 int R_match_sum; int stand=0; int k=1;//守卫k int o[I_sum*2+R_sum+1]; int flag[R_sum],I_match[I_sum],I_location[I_sum]; for(i=0;i<I_sum;i++){ I_match[i]=I_match_flag; I_location[i]=I_location_flag; } for(i=0;i<R_sum;i++){ R_match_sum = 0; for(j=0;j<I_sum;j++){ flag[i] = str_match(I[j],R[i]); if(flag[i]){ //cout<<" <"<<j<<"> "; I_location[j]=j; I_match[j]=I[j]; R_match_sum++; //cout<<" stand="<<stand<<" "<<I[j]<<"."; } } if(R_match_sum){ //cout<<" [start"<<k<<"] "; o[k]=R[i]; k++; o[k]=R_match_sum; k++; for(j=0;j<I_sum;j++){ //cout<<R_match_sum<<" "; if(I_location[j]!=I_location_flag){ R_match_sum--; o[k]=I_location[j]; k++; //cout<<k<<" "; o[k]=I_match[j]; k++; //cout<<k<<". "; I_location[j]=I_location_flag; I_match[j]=I_match_flag; } } //cout<<" ["<<k<<"end] "; } } o[0]=k-1;//(k-1-R_match_sum)/2 //输出o[] for(i=0;i<k;i++){ cout<<o[i]<<" "; } return 0; }
点赞 回复 分享
发布于 2020-05-30 02:57

相关推荐

02-23 00:10
湖南大学 C++
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务