zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    【C#图解教程学习笔记】第13章 委托
    TreeView树,全选,反选,平级选操作
    C# 字符串和字节数组转换
    WebServices 使用Session
    Win8.1下Flash Builder 提示: 找不到所需的Adobe Flash Player调试器版本,解决办法
    C# winform DataGridView 绑定数据的的几种方法
    .NET Core GB2312
    [WPF 学习] 7.2 模板打印
    [WPF 学习] 7.1 多页打印
    [WPF 学习] 7 打印相关的东东
  • 原文地址:https://www.cnblogs.com/hansichen/p/7222225.html
Copyright © 2011-2022 走看看