栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1179 Finding Rectangles

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1179 Finding Rectangles

#include<cstdio>#include<string>#include<vector>#include<algorithm>#include<iostream>using namespace std;namespace{struct Point{char c;int x, y;};bool cmp(const Point *p1, const Point *p2){if (p1->x != p2->x)return p1->x < p2->x;elsereturn p1->y < p2->y;}bool valid(Point *p1, Point *p2, Point *p3, Point *p4){return p1->x == p2->x && p3->x == p4->x && p1->y == p3->y&& p2->y == p4->y;}}int main(){int n, x, y, count = 0;vector<Point*> V;vector<string> res;char s[2];while (scanf("%d", &n), n){getchar();V.clear();res.clear();for (int i = 0; i < n; i++){scanf("%s %d %d", s, &x, &y);Point *p = new Point();p->c = s[0];p->x = x;p->y = y;V.push_back(p);}sort(V.begin(), V.end(), cmp);for (size_t i = 0; i < V.size(); i++)for (size_t j = i + 1; j < V.size(); j++)for (size_t k = j + 1; k < V.size(); k++)for (size_t l = k + 1; l < V.size(); l++)if (valid(V[i], V[j], V[k], V[l])){string str;str.push_back(V[j]->c);str.push_back(V[l]->c);str.push_back(V[k]->c);str.push_back(V[i]->c);res.push_back(str);}sort(res.begin(), res.end());printf("Point set %d:", ++count);if (res.size()){for (size_t i = 0; i < res.size(); i++){if (i % 10 == 0)putchar('n');cout << ' ' << res[i];}putchar('n');}elseputs(" No rectangles");}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/367488.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号