- UID
- 2150
- 帖子
- 8536
- 积分
- 32640
- 阅读权限
- 80
- 注册时间
- 2005-7-22
- 最后登录
- 2014-7-12
- 在线时间
- 6794 小时
- 战队
- [B.D]=
- 种族
- Protoss
- 战队
- [B.D]=
- 种族
- Protoss
|
#include <string>
#include <stdio.h>
#include <vector>
#define COURSE_NUM 5
using namespace std;
using std::vector;
typedef struct stInfo
{
string strStuName;
int nArrayScore[COURSE_NUM];
} SInfo,*PSInfo;
void Split(const string &strValue,const char &strSplit,vector<string> &vectArray)
{
string::const_iterator iterBegin = strValue.begin();
string::const_iterator iterEnd = strValue.end();
while(iterBegin != iterEnd)
{
string::const_iterator iterTemp = iterBegin;
iterBegin = find(iterBegin,iterEnd,strSplit);
vectArray.push_back(string(iterTemp,iterBegin));
if(iterBegin == iterEnd)
{
break;
}
++iterBegin;
}
}
#define MAX_STU_NO 90
int main(int argc,char* argv[])
{
SInfo* oArrayStu[MAX_STU_NO] = {NULL};
//input student info
//"stuname,90,91,92,93,94"
printf("请输入学生姓名,成绩,格式如下:\n");
printf("八达,20,30,50,60,70\n");
while(1)
{
char szInput[50]={0};
scanf("%s",szInput);
if(string(szInput) == "q")
{
break;
}
vector<string> vecInput;
Split(szInput,',',vecInput);
if(vecInput.size() < 2)
{
printf("输入有误,请重新输入!\n");
continue;
}
SInfo* pInfo = new SInfo();
pInfo->strStuName = vecInput[0];
for(int m = 1; m < vecInput.size(); m++)
{
pInfo->nArrayScore[m-1] = atoi(vecInput[m].c_str());
}
//nStuIndex[i] = pInfo;
//该学生成绩
printf("学生:%s,成绩1=[%d],成绩2=[%d],成绩3=[%d],成绩4=[%d],成绩5=[%d]\n",
pInfo->strStuName.c_str(),
pInfo->nArrayScore[0],
pInfo->nArrayScore[1],
pInfo->nArrayScore[2],
pInfo->nArrayScore[3],
pInfo->nArrayScore[4]);
}
return 0;
}
|
|