首页 > 代码库 > 枚举专项练习_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
枚举专项练习_Uva725(Division)_Uva11059(Maximun Product)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。