// Aircraft Maintenance: Lowest Cost // by Seksun Suwanmanee, Dept. of Computer Engineering, Prince of Songkla University // 10 July 2010 #include #include #define MX 100 //maximum number of crews // global variables int ncrew,ntask, task[5*MX][2]={}, //Let's suppose there are at most 5*MX tasks crew[MX][3]={}; char inp[3][MX],taskID[5* MX][MX]; int string2int(char s[]) { int i,r=0,len=strlen(s); for(i=0;i=0;i--) { if(crew[i][0]>=level) if(minCost>crew[i][1]) { minCost=crew[i][1]; minCrew=i; } } return minCrew; } int getMin(int x, int y) { return (x<=y?x:y) ; } int getMax(int x, int y) { return (x>=y?x:y) ; } int main() { int i,j, totalCost, minWHrs; //local test //freopen("smallinput.txt","r",stdin); //freopen("inputSample.txt","r",stdin); //freopen("inputTest.txt","r",stdin); //freopen("Dinput.txt","r",stdin); // Reading the input ncrew=0; ntask=0; while( scanf("%s %s %s",inp[0],inp[1],inp[2]) == 3 ) { // crew information begins with number if (inp[0][0]>='0' && inp[0][0]<='9') { i=string2int(inp[0]); // crew number crew[i][0]=string2int(inp[1]); // crew skill level crew[i][1]=string2int(inp[2]); // crew cost per hour crew[i][2]=0; // initial working hours = 0 for all crew ncrew++; } else // task information { strcpy(taskID[ntask],inp[0]); //task ID task[ntask][0]=string2int(inp[1]); // task level task[ntask][1]=string2int(inp[2]); // task hours ntask++; } } //show input data for(i=0;i=0;i--) { j=getLowestCrew(task[i][0]); totalCost+=task[i][1]*crew[j][1]; //printf("%s %d %d*%d\n",taskID[i], task[i][0],task[i][1], crew[j][1]); } printf("Lowest cost = "); printf("%d\n",totalCost); // */ //getch(); return 0; }