Skip to content

Instantly share code, notes, and snippets.

@0x2f0713
Last active May 14, 2018 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0x2f0713/050946089ed80d7681a19795e2f6b33c to your computer and use it in GitHub Desktop.
Save 0x2f0713/050946089ed80d7681a19795e2f6b33c to your computer and use it in GitHub Desktop.

Có bao nhiêu số tự nhiên gồm 4 chữ số sao cho không có chữ số nào lặp lại đúng 3 lần.

#include <iostream>
#include <stdio.h>
int main(int argc, char const *argv[])
{
int count;
int countnumber = 0;
int esc;
for (int i = 1; i <= 9; i++)
{
for (int j = 0; j <= 9; j++)
{
for (int k = 0; k <= 9; k++)
{
for (int l = 0; l <= 9; l++)
{
/* Ví dụ số: 1110, 1101, 1011, 2011 */
if (i == j)
{
count++;
}
if (j == k)
{
count++;
}
if (k == l)
{
count++;
}
if (i == k)
{
count++;
}
if (i == l)
{
count++;
}
if (j == l)
{
count++;
}
if (count >= 3 and count <= 4)
{
countnumber++;
std::cout << i << j << k << l << " " << countnumber << std::endl;
}
count = 0;
}
}
}
}
countnumber++;
std::cout << "Tong cong co: " << countnumber << " so" << std::endl;
return 0;
}
1011 1
1101 2
1110 3
1112 4
1113 5
1114 6
1115 7
1116 8
1117 9
1118 10
1119 11
1121 12
1131 13
1141 14
1151 15
1161 16
1171 17
1181 18
1191 19
1211 20
1222 21
1311 22
1333 23
1411 24
1444 25
1511 26
1555 27
1611 28
1666 29
1711 30
1777 31
1811 32
1888 33
1911 34
1999 35
2000 36
2022 37
2111 38
2122 39
2202 40
2212 41
2220 42
2221 43
2223 44
2224 45
2225 46
2226 47
2227 48
2228 49
2229 50
2232 51
2242 52
2252 53
2262 54
2272 55
2282 56
2292 57
2322 58
2333 59
2422 60
2444 61
2522 62
2555 63
2622 64
2666 65
2722 66
2777 67
2822 68
2888 69
2922 70
2999 71
3000 72
3033 73
3111 74
3133 75
3222 76
3233 77
3303 78
3313 79
3323 80
3330 81
3331 82
3332 83
3334 84
3335 85
3336 86
3337 87
3338 88
3339 89
3343 90
3353 91
3363 92
3373 93
3383 94
3393 95
3433 96
3444 97
3533 98
3555 99
3633 100
3666 101
3733 102
3777 103
3833 104
3888 105
3933 106
3999 107
4000 108
4044 109
4111 110
4144 111
4222 112
4244 113
4333 114
4344 115
4404 116
4414 117
4424 118
4434 119
4440 120
4441 121
4442 122
4443 123
4445 124
4446 125
4447 126
4448 127
4449 128
4454 129
4464 130
4474 131
4484 132
4494 133
4544 134
4555 135
4644 136
4666 137
4744 138
4777 139
4844 140
4888 141
4944 142
4999 143
5000 144
5055 145
5111 146
5155 147
5222 148
5255 149
5333 150
5355 151
5444 152
5455 153
5505 154
5515 155
5525 156
5535 157
5545 158
5550 159
5551 160
5552 161
5553 162
5554 163
5556 164
5557 165
5558 166
5559 167
5565 168
5575 169
5585 170
5595 171
5655 172
5666 173
5755 174
5777 175
5855 176
5888 177
5955 178
5999 179
6000 180
6066 181
6111 182
6166 183
6222 184
6266 185
6333 186
6366 187
6444 188
6466 189
6555 190
6566 191
6606 192
6616 193
6626 194
6636 195
6646 196
6656 197
6660 198
6661 199
6662 200
6663 201
6664 202
6665 203
6667 204
6668 205
6669 206
6676 207
6686 208
6696 209
6766 210
6777 211
6866 212
6888 213
6966 214
6999 215
7000 216
7077 217
7111 218
7177 219
7222 220
7277 221
7333 222
7377 223
7444 224
7477 225
7555 226
7577 227
7666 228
7677 229
7707 230
7717 231
7727 232
7737 233
7747 234
7757 235
7767 236
7770 237
7771 238
7772 239
7773 240
7774 241
7775 242
7776 243
7778 244
7779 245
7787 246
7797 247
7877 248
7888 249
7977 250
7999 251
8000 252
8088 253
8111 254
8188 255
8222 256
8288 257
8333 258
8388 259
8444 260
8488 261
8555 262
8588 263
8666 264
8688 265
8777 266
8788 267
8808 268
8818 269
8828 270
8838 271
8848 272
8858 273
8868 274
8878 275
8880 276
8881 277
8882 278
8883 279
8884 280
8885 281
8886 282
8887 283
8889 284
8898 285
8988 286
8999 287
9000 288
9099 289
9111 290
9199 291
9222 292
9299 293
9333 294
9399 295
9444 296
9499 297
9555 298
9599 299
9666 300
9699 301
9777 302
9799 303
9888 304
9899 305
9909 306
9919 307
9929 308
9939 309
9949 310
9959 311
9969 312
9979 313
9989 314
9990 315
9991 316
9992 317
9993 318
9994 319
9995 320
9996 321
9997 322
9998 323
Tong cong co: 324 so
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment