问题及代码:
/*
* Copyright (c) 2014, 烟台大学计算机学院
* All rights reserved.
* 文件名称:test.cpp
* 作 者:尚月
* 完成日期:2014年 10 月30 日
* 版 本 号:v1.0
*
* 问题描述:统计血型
* 输入描述:输入血型序列 (A/B/O/C,C代表AB型血,输入以X结束)
* 程序输出:各种血型的数量
*/
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int a=0,b=0,ab=0,o=0;
char blood;
cin >>blood;
while(blood!='X')
{
switch(blood)
{
case 'A':
a++;
break;
case 'B':
b++;
break;
case 'C':
ab++;
break;
case 'O':
o++;
break;
}
cin>>blood;
}
cout<<"A:"<<a<<" "<<endl;
cout<<"B:"<<b<<" "<<endl ;
cout<<"O:"<<o<<" "<< endl;
cout<<"AB:"<<ab<<" "<<endl ;
return 0;
}