枚举专项练习_Uva725(Division)_Uva11059(Maximun Product)

Posted 豆子

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了枚举专项练习_Uva725(Division)_Uva11059(Maximun Product)相关的知识,希望对你有一定的参考价值。

 1 //Uva725
 2 #include <iostream>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <cstdio>
 6 using namespace std;
 7 
 8 void evalu(int n)
 9 {
10     const int maxn = 1024 + 10;
11     char num[10];                      //将数字用字符保存
12     int flag[10];                      //判断每个数,是否重复 
13     char buf[maxn];                    //将出现的字符全部存到里面 
14     for (int i = 1234; i <= 5000; i++)
15     {
16         memset(flag, 0, sizeof(flag));
17         memset(num, 0, sizeof(num));
18         sprintf(num, "%05d", i);
19 //        cout << "Debug: " << num << endl;
20 //        system("pause");
21         int digit = 0, rest = 0;
22         digit = (num[0]-0)*10000 + (num[1]-0)*1000 + (num[2]-0)*100 + (num[3]-0)*10 + (num[4]-0);
23 //        cout << "Debug:digit: " << digit << endl;
24 //        system("pause");
25         rest = digit * n;
26         sprintf(buf, "%05d%05d", rest, digit);
27         int len = strlen(buf), j = 0;
28         for (j = 0; j < len; j++) {
29             if (flag[buf[j] - 0]) {
30                 break;
31             }
32             else {
33                 flag[buf[j] - 0] = 1;
34             }
35         }
36         if (j == len) {
37             cout << rest << " / " << num << " = " << n << endl;
38         }
39     }    
40 }
41 
42 
43 int main()
44 {
45     int num;
46     while (cin >> num) {
47         evalu(num);
48     }    
49     return 0;
50 }
 1 //Uva11059
 2 #include <iostream>
 3 #include <vector>
 4 #include <cstdio>
 5 #include <cstdlib>
 6 #include <fstream>
 7 using namespace std;
 8 
 9 //ifstream in("in.txt");
10 //ofstream out("out.txt");
11 
12 int main()
13 {
14     long long pro = 1, max_pro = 0;
15     vector<long long> num;
16     long long data;
17     int T, kase = 0;
18     while (cin >> T) 
19     {
20         num.clear();
21         pro = max_pro = 0;
22         while (T--) {
23             cin >> data; num.push_back(data);
24         }    
25         for (unsigned i = 0; i < num.size(); i++) {
26             pro = num[i];
27             for (unsigned j = i; j < num.size(); j++) {
28                 if (i != j) {  
29                     pro *= num[j];            //pro尽管乘 
30                     if (pro > num[i])         //pro > num[i] 
31                         num[i] = pro;         //num[i] = pro, 将最大的乘积放到该位置
32                 }
33             }
34         }
35         for (unsigned i = 0; i < num.size(); i++) {
36             if (num[i] > max_pro) {
37                 max_pro = num[i];
38             }
39         }
40         cout << "Case #" << ++kase << ": The maximum product is " << max_pro << "." << "\n\n";
41     } 
42     return 0;
43 }
44  

 

以上是关于枚举专项练习_Uva725(Division)_Uva11059(Maximun Product)的主要内容,如果未能解决你的问题,请参考以下文章

UVA - 725 Division

Division UVa725

uva 725 Division

UVA 725 Division

Uva 725 Division

Division