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

枚举专项练习_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  

 

posted @ 2017-01-19 23:45 douzujun 阅读( ...) 评论( ...) 编辑 收藏
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值