• hdu 2561~2566 水题集合


    2561:

     1 #include <iostream>
     2 #include <cstring>
     3 using namespace std;
     4 
     5 const int N = 10;
     6 int num[N];
     7 
     8 int main()
     9 {
    10     int t;
    11     cin >> t;
    12     while ( t-- )
    13     {
    14         int n;
    15         cin >> n;
    16         for ( int i = 0; i < n; i++ )
    17         {
    18             cin >> num[i];
    19         }
    20         int tmp = 0;
    21         for ( int i = 1; i < n; i++ )
    22         {
    23             if ( num[tmp] > num[i] ) tmp = i;
    24         }
    25         num[tmp] = 100;
    26         tmp = 0;
    27         for ( int i = 1; i < n; i++ )
    28         {
    29             if ( num[tmp] > num[i] ) tmp = i;
    30         }
    31         cout << num[tmp] << endl;
    32     }
    33     return 0;
    34 }

    2562:

     1 #include <iostream>
     2 #include <cstring>
     3 using namespace std;
     4 
     5 const int N = 51;
     6 char num[N];
     7 
     8 int main()
     9 {
    10     int t;
    11     cin >> t;
    12     while ( t-- )
    13     {
    14         cin >> num;
    15         int len = strlen(num);
    16         for ( int i = 0; i < len - 1; i += 2 )
    17         {
    18             swap( num[i], num[i + 1] );
    19         }
    20         cout << num << endl;
    21     }
    22     return 0;
    23 }

    2563:

     递推咯。

     1 #include <iostream>
     2 using namespace std;
     3 
     4 const int N = 21;
     5 int f[N];
     6 
     7 void get()
     8 {
     9     f[0] = 1;
    10     f[1] = 3;
    11     for ( int i = 2; i < N; i++ )
    12     {
    13         f[i] = f[i - 1] * 2 + f[i - 2];
    14     }
    15 }
    16 
    17 int main ()
    18 {
    19     get();
    20     int t;
    21     cin >> t;
    22     while ( t-- )
    23     {
    24         int n;
    25         cin >> n;
    26         cout << f[n] << endl;
    27     }
    28     return 0;
    29 }

    2564:

     1 #include <cstring>
     2 #include <cstdio>
     3 #include <cctype>
     4 using namespace std;
     5 
     6 const int N = 101;
     7 char word[N];
     8 
     9 int main ()
    10 {
    11     int t;
    12     scanf("%d", &t);
    13     getchar();
    14     while ( t-- )
    15     {
    16         gets(word);
    17         int len = strlen(word);
    18         for ( int i = 0; i < len; i++ )
    19         {
    20             if ( isalpha(word[i]) )
    21             {
    22                 char ch = toupper(word[i]);
    23                 printf("%c", ch);
    24                 do
    25                 {
    26                     i++;
    27                 } while ( isalpha(word[i]) );
    28             }
    29         }
    30         puts("");
    31     }
    32     return 0;
    33 }

    2565:

    这个题的格式真是坑...

     1 #include <cstring>
     2 #include <cstdio>
     3 #include <cctype>
     4 using namespace std;
     5 
     6 const int N = 100;
     7 char grid[N][N];
     8 
     9 void make( int n )
    10 {
    11     for ( int i = 0; i < n; i++ )
    12         for ( int j = 0; j < n; j++ )
    13             grid[i][j] = ' ';
    14     int k = 0;
    15     while ( k < n )
    16     {
    17         grid[k][k] = 'X';
    18         k++;
    19     }
    20     k = n - 1;
    21     while ( k > -1 )
    22     {
    23         grid[k][n - 1 - k] = 'X';
    24         k--;
    25     }
    26 }
    27 
    28 void out( int n )
    29 {
    30     for ( int i = 0; i < n; i++ )
    31     {
    32         int cnt = 0;
    33         for ( int j = 0; j < n; j++ )
    34         {
    35             printf("%c", grid[i][j]);
    36             if ( grid[i][j] == 'X' )
    37             {
    38                 if ( i == n / 2 )
    39                 {
    40                     break;
    41                 }
    42                 cnt++;
    43                 if ( cnt == 2 ) break;
    44             }
    45         }
    46         puts("");
    47     }
    48     puts("");
    49 }
    50 
    51 int main ()
    52 {
    53     int t;
    54     scanf("%d", &t);
    55     while ( t-- )
    56     {
    57         int n;
    58         scanf("%d", &n);
    59         make(n);
    60         out(n);
    61     }
    62     return 0;
    63

    2566:

    没有数据范围的流氓题,果断枚举水之。

     1 #include <iostream>
     2 using namespace std;
     3 
     4 int main ()
     5 {
     6     int t;
     7     cin >> t;
     8     while ( t-- )
     9     {
    10         int n, m;
    11         cin >> n >> m;
    12         int cnt = 0;
    13         for ( int i = 0; i <= n; i++ )
    14         {
    15             for ( int j = 0; j <= n - i; j++ )
    16             {
    17                 int k = n - i - j;
    18                 if ( i + j * 2 + k * 5 == m ) cnt++;
    19             }
    20         }
    21         cout << cnt << endl;
    22     }
    23     return 0;
    24 }
  • 相关阅读:
    ch_6802 車的放置
    ch_POJ2182 Lost Cows
    ch_4201 楼兰图腾
    luogu_P3368【模板】树状数组 2
    门面
    建造者
    模板方法
    状态
    抽象工厂
    工厂方法
  • 原文地址:https://www.cnblogs.com/huoxiayu/p/4445700.html
Copyright © 2020-2023  润新知