Aizu 2780 Best Matched Pair
来源:互联网 发布:知天下事打一生肖 编辑:程序博客网 时间:2024/05/21 09:05
/*此题是一个序列中任意两个数相乘,除了自己和自己以外得到的最大的数且该数字是类似于“1234”连续上升的*/#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <map>#include <set>using namespace std;int num[1010];int main(){ int n; while(scanf("%d", &n) != EOF){ set <int > ss; char s[1010]; for(int i = 0; i < n; i++){ scanf("%d", &num[i]); } int sum; int cc = 0; for(int i = 0; i < n-1; i++){ for(int j = i+1; j < n; j++){ sum = num[i]*num[j]; int cnt = 0; sprintf(s, "%d", sum); for(int l = 0; l < strlen(s)-1; l++) { if(s[l+1] - s[l] == 1) cnt++; } if(cnt == strlen(s) - 1) ss.insert(sum); } } int maxn = 0; if(!ss.size()) { cout << "-1" << endl; continue; } for(set<int> :: iterator it = ss.begin(); it != ss.end(); it++){//这里是用了set爱找字典序排序的特点 maxn = max(maxn, *it); } cout << maxn << endl; }}
0 0
- Aizu 2780 Best Matched Pair
- BNU Problem A Best Matched Pair
- [JAG practice] A - Best Matched Pair 遍历+水题
- (2016弱小联盟十一专场10.3) Best Matched Pair 暴力
- 2016 ACM-ICPC Asia Regional A – Best Matched Pair(打表)
- 2016弱校联盟十一专场10.3 ABest Matched Pair(水)
- Aizu
- Aizu
- Aizu
- Aizu
- Aizu
- Aizu
- Aizu
- Aizu
- Aizu
- Aizu
- pair
- pair
- shell的数值运算方法
- bzoj2179: FFT快速傅立叶
- Rescue (BFS 优先队列)
- bzoj2194: 快速傅立叶之二
- opencv(8)---访问图像像素
- Aizu 2780 Best Matched Pair
- java I/O 之读取InputStream数据到内存&&内存数据写入到OutputSteam中
- bzoj4259: 残缺的字符串
- 使用bootstrap-select 动态加载数据不显示的问题
- bzoj3527: [Zjoi2014]力
- .NET产品源码保护,.NET防止反编译,c#/vb.net 防反编译
- 指针函数与函数指针
- LEETCODE 15&&16
- (10)caffe总结之运行caffe自带的两个简单例子