码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-01-20 00:25:10      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:rest   color   ase   fstream   style   --   cstring   数字   namespace   

 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)

标签:rest   color   ase   fstream   style   --   cstring   数字   namespace   

原文地址:http://www.cnblogs.com/douzujun/p/6309097.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!