首页 > 代码库 > TOJ1056: 英文金曲大赛

TOJ1056: 英文金曲大赛

Time Limit Exceeded:

技术分享
 1 #include<iostream>
 2 #include<string>
 3 #include<iomanip>
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     string s;
 9     double a[7];
10     while (1)
11     {
12         double sum = 0;
13         for (int i = 0;i < 7;++i)
14         {
15             cin >> a[i];
16             sum += a[i];
17         }
18         cin >> s;
19         for (int j = 0;j < 7;++j)
20         {
21             for (int k = j;k < 7;k++)
22             {
23                 if (a[j] > a[k])
24                 {
25                     double temp;
26                     temp = a[j];a[j] = a[k];a[k] = temp;
27                 }
28             }
29         }
30         cout << s<<" ";
31         sum=sum - a[0] - a[6];
32         cout << setiosflags(ios::fixed)<<setprecision(2)<<sum/5 << endl;
33     }
34     return 0;
35 }
选择排序
技术分享
 1 #include<iostream>
 2 #include<string>
 3 #include<iomanip>
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     string s;
 9     double a[7];
10     while (1)
11     {
12         double sum = 0;
13         for (int i = 0;i < 7;++i)
14         {
15             cin >> a[i];
16             sum += a[i];
17         }
18         cin >> s;
19         for (int j = 1;j < 7;++j)
20         {
21             if (a[j] >= a[j - 1])
22             {
23                 double temp;
24                 temp = a[j];a[j] = a[j - 1];a[j - 1] = temp;
25             }
26         }
27         cout << s<<" ";
28         sum=sum - a[0] - a[6];
29         cout << setiosflags(ios::fixed)<<setprecision(2)<<sum/5 << endl;
30     }
31     return 0;
32 }
冒泡排序

Accepted:

技术分享
 1 #include<iostream>
 2 #include<string>
 3 #include<iomanip>
 4 using namespace std;
 5 
 6 void sort(double a[])
 7 {
 8     for (int j = 0;j < 7;++j)
 9     {
10         for (int k = j;k < 7;k++)
11         {
12             if (a[j] > a[k])
13             {
14                 double temp;
15                 temp = a[j];a[j] = a[k];a[k] = temp;
16             }
17         }
18     }
19 }
20 
21 int main()
22 {
23     string s;
24     double a[7];
25     while ((scanf("%lf",&a[0]))!=EOF)
26     {
27         double sum = 0;
28         for (int i = 1;i < 7;++i)
29         {
30             cin >> a[i];
31         }
32         cin >> s;
33         sort(a);
34         cout << s<<" ";
35         for (int ii = 1;ii < 6;++ii)
36             sum += a[ii];
37         cout << setiosflags(ios::fixed)<<setprecision(2)<<sum/5 << endl;
38     }
39     return 0;
40 }
View Code

 

TOJ1056: 英文金曲大赛