online_judge_1178

63 篇文章 0 订阅
#include <stdio.h>
#include <stdlib.h>
#define M 1000
int size;
typedef struct Fushu
{
    int a;
    int b;
}Fushu;
void fupop(Fushu *c)
{
    int i,t=0;
    int max=c[0].a*c[0].a+c[0].b*c[0].b;
    for(i=1;i<size;i++)
    {
        if((c[i].a*c[i].a+c[i].b*c[i].b)>max)
        {
            max=c[i].a*c[i].a+c[i].b*c[i].b;
            t=i;
        }
        else if((c[i].a*c[i].a+c[i].b*c[i].b)==max&&c[i].a>c[t].a)
            t=i;
    }
    printf("%d+i%d\n",c[t].a,c[t].b);
    printf("SIZE = %d\n",--size);
    for(i=t;i<size;i++) c[i]=c[i+1];
}
void Insert(Fushu *c,char *s)
{
    int x,y,i;
    x=s[7]-'0';i=8;
    while(s[i]!='+') x=10*x+s[i++]-'0';
    y=s[i+2]-'0';
    while(s[i+3]!='\0') y=y*10+s[i++ +3]-'0';
    c[size].a=x; c[size].b=y;
    size++;
    printf("SIZE = %d\n",size);
}
int main()
{
    int n,i;
    char str[20];
    Fushu d[M];
    while(scanf("%d",&n)!=EOF)
    {
        getchar();
        if(n<1||n>M) continue;
        i=0;#include <stdio.h>
#include <stdlib.h>
#define M 1000
int size;
typedef struct Fushu
{
    int a;
    int b;
}Fushu;
void fupop(Fushu *c)
{
    int i,t=0;
    int max=c[0].a*c[0].a+c[0].b*c[0].b;
    for(i=1;i<size;i++)
    {
        if((c[i].a*c[i].a+c[i].b*c[i].b)>max)
        {
            max=c[i].a*c[i].a+c[i].b*c[i].b;
            t=i;
        }
        else if((c[i].a*c[i].a+c[i].b*c[i].b)==max&&c[i].a>c[t].a)
            t=i;
    }
    printf("%d+i%d\n",c[t].a,c[t].b);
    printf("SIZE = %d\n",--size);
    for(i=t;i<size;i++) c[i]=c[i+1];
}
void Insert(Fushu *c,char *s)
{
    int x,y,i;
    x=s[7]-'0';i=8;
    while(s[i]!='+') x=10*x+s[i++]-'0';
    y=s[i+2]-'0';
    while(s[i+3]!='\0') y=y*10+s[i++ +3]-'0';
    c[size].a=x; c[size].b=y;
    size++;
    printf("SIZE = %d\n",size);
}
int main()
{
    int n,i;
    char str[20];
    Fushu d[M];
    while(scanf("%d",&n)!=EOF)
    {
        getchar();
        if(n<1||n>M) continue;
        i=0;
        size=0;
        while(i<n)
        {
            gets(str);
            if(str[0]=='P')
            {
                if(size==0) printf("empty\n");
                else fupop(d);
            }
            else if(str[0]=='I')
                Insert(d,str);
            i++;
        }
    }
    return 0;
}

        size=0;
        while(i<n)
        {
            gets(str);
            if(str[0]=='P')
            {
                if(size==0) printf("empty\n");
                else fupop(d);
            }
            else if(str[0]=='I')
                Insert(d,str);
            i++;
        }
    }
    return 0;
}
这次代码很杂,但是逻辑思路较以前更加清晰了!继续加油。。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值