标签:
一、题目要求
#include<iostream.h> void ID_array(int l,int A[]) { cout<<"请输入ID序列:"<<endl; for(int i=0;i<l;i++) { cin>>A[i]; } } int main() { int l;//长度 int target[3]={0,0,0}; int ID[3]={-1,-1,-1}; cout<<"请输入的帖子数量:"; cin>>l; int * shuiwang=new int [l]; ID_array(l,shuiwang); for(int i=0;i<l;i++) { if(target[0]==0 && shuiwang[i]!=ID[1] && shuiwang[i]!=ID[2]) { target[0]=1; ID[0]=shuiwang[i]; } else if(target[1]==0 && shuiwang[i]!=ID[0] && shuiwang[i]!=ID[2]) { target[1]=1; ID[1]=shuiwang[i]; } else if(target[2]==0 && shuiwang[i]!=ID[0] && shuiwang[i]!=ID[1]) { target[2]=1; ID[2]=shuiwang[i]; } else if(shuiwang[i]!=ID[0] && shuiwang[i]!=ID[1] && shuiwang[i]!=ID[2]) { target[0]--; target[1]--; target[2]--; } else if(shuiwang[i]==ID[0]) { target[0]++; } else if(shuiwang[i]==ID[1]) { target[1]++; } else if(shuiwang[i]==ID[2]) { target[2]++; } } cout<<"水王一为:"<<ID[0]<<endl; cout<<"水王二为:"<<ID[1]<<endl; cout<<"水王三为:"<<ID[2]<<endl; return 0; }
四、截图
五、总结
通过这次实验,将”消消乐“思想再次强化运用,虽然这次题目更复杂,但是技巧用的好也很容易实现。
标签:
原文地址:http://www.cnblogs.com/2015tan/p/4466828.html