更新时间:2022-09-18 15:05:53
#include<iostream> using namespace std; class animalword { public: int ID; int X; int Y; animalword(){}; animalword(int i,int j,int k){ ID=i; X=j; Y=k;} ~animalword(){} bool judge(int N){ if((X>N)||(Y>N)) return false; else return true; } }; struct True_Word { int X; int Y; int judge; }; int main() { int N,K; cout<<"input the number of animal and true words:"<<endl; cin>>N>>K; cout<<endl; animalword *word=new animalword[K]; cout<<"input data:"<<endl; for(int i=0;i<K;i++) { int id,x,y; cin>>id>>x>>y; word[i].ID=id; word[i].X=x; word[i].Y=y; } cout<<"the inputed data is:"<<endl; for(int i=0;i<K;i++) cout<<word[i].ID<<" "<<word[i].X<<" "<<word[i].Y<<endl; string s="\0"; True_Word* true_word=new True_Word[N]; int num=0; for(int i=0;i<K;i++) { if(word[i].judge(N)) { int j; for(j=0;j<num;j++) { if((true_word[j].X==word[i].X)&&(true_word[j].Y==word[i].Y)&&(true_word[j].judge!=word[i].ID)) break; else if((true_word[j].X==word[i].Y)&&(true_word[j].Y==word[i].X)&&(true_word[j].judge==word[i].ID)) break; } if(j==num) { true_word[num].X=word[i].X; true_word[num].Y=word[i].Y; true_word[num].judge=word[i].ID; num++; } } } int false_num=N-num; cout<<"the false word number is:"<<false_num<<endl; delete [] true_word; delete [] word; return 0; }
如何存储食物链的信息 应该是把所有物种分类后才能识别这些信息,但是如何存储目前还没有想的好的办法
本文转自cococo点点博客园博客,原文链接:http://www.cnblogs.com/coder2012/archive/2012/10/09/2716036.html,如需转载请自行联系原作者