1. Question:
Description
In Naruto, Yile ramen is the favorite of Naruto. Coincidentally, today is the day when the Naruto is promoted to a tolerable state (after so many years, he finally succeeded to endure =). He decided to take his friends to a great meal to celebrate.
When I arrived at Yile's door, I was stunned. There were already several teams in the door, and there were still many people in each team. Naruto is already hungry. He wants to know which team can eat as soon as possible.
There are three types of people in the queue, and each type of food is made at different times. The details are as follows:
A kind of people: I have never passed the exam. A person is sad to come out and have A boring meal. This kind of person will order 1 bowl of ramen + 1 piece of barbecue + 1 cup of drinks.
Type B: A smiling couple, both of whom have passed the medium endurance test. They will order 2 bowls of ramen + 1 piece of barbecue.
C: A family of three, two middle-aged people with a child, watching the audience who endured the test, they will order 3 bowls of ramen + 3 barbecues + 2 drinks.
The production time of each type of food is provided in the input requirement.
Input Format
The input contains multiple groups of test data.
Enter four positive integers n, l, k, y, n in the first row of each group to indicate the number of columns of the team, l to indicate the time when the ramen was created, and k to indicate the time when the barbecue was created, y indicates the time when the beverage was created. All positive integers are within the 32-bit int range.
In the next n rows, each line enters A string to indicate the queue status of the team. The string consists of only letters A, B, and C. Each letter corresponds to A person in the topic description, the length of a string cannot exceed 100.
Output
For each group of input, the output will display the queuing time of the team that the Naruto can eat as soon as possible.
Sample Input
3 3 4 1
ABCABC
AACC
ACBAA
Sample output
57
2. Code 1:
#include <iostream>#include <string.h>#include <algorithm>using namespace std;int main(){ int i, j, n, l, k, y, a, b, c, sum[100]; char s[100]; while (cin >> n >> l >> k >> y) { a = l + k + y; b = 2 * l + k; c = 3 * l + 3 * k + 2 * y; for (j = 0; j < n; j++) { cin >> s; sum[j] = 0; for (i = 0; i < strlen(s); i++) { if (s[i] == 'A') sum[j] += a; else if (s[i] == 'B') sum[j] += b; else if (s[i] == 'C') sum[j] += c; } } sort(sum, sum + n); cout << sum[0] << endl; } return 0;}
Code 2:
#include <stdio.h>int main(){ int n, l, k, y, i, mini, t; char s[101]; while (scanf("%d%d%d%d", &n, &l, &k, &y) != EOF) { mini = 1000000000; while (n--) { scanf("%s", s); for (t = i = 0; s[i]; i++) { if (s[i] == 'A') t += l + k + y; else if (s[i] == 'B') t += l * 2 + k; else t += l * 3 + k * 3 + y * 2; } if (t < mini) mini = t; } printf("%d\n", mini); } return 0;}