zoukankan      html  css  js  c++  java
  • 求符合给定条件的整数集

     1 /*
     2     求符合给定条件的整数集
     3 */
     4 
     5 #include <stdio.h>
     6 
     7 int main()
     8 {
     9     int n;
    10     int cnt = 0;
    11     int hundred, ten, unit;
    12 
    13     scanf_s("%d", &n);
    14     
    15     for (int i = 100; i < 1000; i++)
    16     {
    17         hundred = i / 100;
    18         ten = i % 100 / 10;
    19         unit = i % 10;
    20 
    21         if (hundred == ten || ten == unit || hundred == unit)
    22         {
    23             continue;
    24         }
    25 
    26         if (hundred >= n && hundred <= n+3)
    27         {
    28             if (ten >= n && ten <= n + 3)
    29             {
    30                 if(unit >= n && unit <= n + 3)
    31                 {
    32                     printf("%d", i);
    33                     cnt++;
    34                     if (cnt < 6)
    35                     {
    36                         printf(" ");
    37                     }
    38                     else
    39                     {
    40                         if (cnt == 6)
    41                         {
    42                             printf("
    ");
    43                             cnt = 0;
    44                         }
    45                     }
    46                 }
    47             }            
    48         }
    49     }
    50 
    51     return 0;
    52 }

     修改版

     1 #include <stdio.h>
     2 
     3 int main()
     4 {
     5     int a;
     6     scanf_s("%d", &a);
     7     int i, j, k;
     8     int cnt = 0;
     9 
    10     for (i = a; i <= a+3; i++)
    11     {
    12         for (j = a; j <= a + 3; j++)
    13         {
    14             for (k = a; k <= a + 3; k++)
    15             {
    16                 if (i != j && j != k && i != k)
    17                 {
    18                     printf("%d", i * 100 + j * 10 + k);
    19                     cnt++;
    20                     if (cnt < 6)
    21                     {
    22                         printf(" ");
    23                     }
    24                     else
    25                     {
    26                         if (cnt == 6)
    27                         {
    28                             printf("
    ");
    29                             cnt = 0;
    30                         }
    31                     }
    32                 }
    33             }
    34         }
    35     }
    36 
    37     return 0;
    38 }
  • 相关阅读:
    HDU6216
    HDU6213
    HDU6191(01字典树启发式合并)
    HDU4825(01字典树)
    HDU5293(SummerTrainingDay13-B Tree DP + 树状数组 + dfs序)
    HDU2196(SummerTrainingDay13-D tree dp)
    HDU6201
    HDU6205
    HDU6195
    ffmpeg.编译20200719
  • 原文地址:https://www.cnblogs.com/2018jason/p/10950660.html
Copyright © 2011-2022 走看看