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

zoj 1123 Triangle Encapsulation

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

zoj 1123 Triangle Encapsulation

#include <stdio.h>#ifndef __min#define __min(a, b) ((a)<(b)? (a):(b))#endif#ifndef __max#define __max(a, b) ((a)>(b)? (a):(b))#endiftypedef struct _tagPOINT{    char x;    char y;} POINT;POINT pts[90];int pts_top; int Direction(int xi, int yi,   int xj, int yj,   int xk, int yk){    return (xk-xi)*(yj-yi) - (xj-xi)*(yk-yi);}int main(int argc, char* argv[]){    int x0, y0, x1, y1, x2, y2, x, y;    int left, top, right, bottom;    int min_x, i, j, cur_y;    printf("Program 4 by team Xn");    while(scanf("%d %d %d %d %d %d",        &x0, &y0, &x1, &y1, &x2, &y2) != EOF)    {        pts_top = -1;        min_x  = 10;        left = __min(__min(x0, x1), x2);        top = __max(__max(y0, y1), y2);        right = __max(__max(x0, x1), x2);        bottom = __min(__min(y0, y1), y2);         for(y = top; y >= bottom; y--)        { for(x = left; x <= right; x++) {     if( Direction(x0, y0, x1, y1, x, y) <= 0) continue;     if( Direction(x1, y1, x2, y2, x, y) <= 0) continue;     if( Direction(x2, y2, x0, y0, x, y) <= 0) continue;        ++pts_top;     pts[pts_top].x = x;     pts[pts_top].y = y;       if(x < min_x) min_x = x; }        }         cur_y = -10;          for(i = 0; i <= pts_top; i++)        { if(pts[i].y != cur_y)  {     cur_y = pts[i].y;       if(i > 0) printf("n");       for(j = 0; j < ( pts[i].x - min_x ) * 9; j++)         printf(" "); } else {        if(i > 0) printf(" "); } printf("(%2d, %2d)", pts[i].x, pts[i].y);        }         printf("nn");    }    printf("End of program 4 by team Xn");    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/380160.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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