结构体数组应用举例

 1 #include <iostream>
 2 #include <string.h>
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 
 6 struct Person
 7 {
 8     string name;
 9     int count;
10 };
11 
12 int main(int argc, char** argv) {
13     Person leader[3]={"Li",0,"Zhang",0,"Fun",0};
14     int i,j;
15     string leader_name;
16     for(i=0;i<10;i++)
17     {
18         cin>>leader_name;
19         for(j=0;j<3;j++)
20         if(leader_name==leader[j].name)leader[j].count++;
21         }    
22     cout<<endl;
23     for(i=0;i<3;i++)
24     {
25         cout<<leader[i].name<<":"<<leader[i].count<<endl;
26     }
27     return 0;
28 }

 

posted @ 2018-08-01 16:00  borter  阅读(379)  评论(0编辑  收藏  举报