大整数的最大值最小值判断

来源:互联网 发布:千年 升段 算法 编辑:程序博客网 时间:2024/06/05 15:00
#include <stdio.h>#include <stdlib.h>#include <string.h>#define N 1500int main(){    long long int templeng,lengmax,lengmin,i,start = 0,end,j,k = 0,yxleng;    char temp[N],max[N],min[N];    while(scanf("%s",temp) != EOF)    {        start = 0;        templeng = strlen(temp);        int pdx = 0;        for(i = 0; i < templeng; i++)        {            if(temp[i] > '0' && temp[i] <= '9')            {                start = i;                pdx = 1;                break;            }        }        if(pdx == 0)        {            memset(temp,0,sizeof(temp));            temp[0] = '0';            templeng = 1;            start = 0;        }        k++;        yxleng = templeng - start;        if(k == 1)        {            lengmax = yxleng;            lengmin = yxleng;            memcpy(max,temp+start,1500);            memcpy(min,temp+start,1500);        }        if(k > 1)        {            if(yxleng > lengmax)            {                memcpy(max,temp + start,1500);                lengmax = yxleng;                goto loop;            }            if(yxleng == lengmax)            {                for(j = 0; j < lengmax; j++)                {                    if(temp[start+j] < max[j])                    {                        goto loop;                    }                    if(temp[start+j] > max[j])                    {                        memcpy(max,temp + start,1500);                        lengmax = yxleng;                        goto loop;                    }                }            }            if(yxleng < lengmin)            {                memcpy(min,temp + start,1500);                lengmin = yxleng;                goto loop;            }            if(yxleng == lengmin)            {                int pd = 0;                for(j = 0; j < lengmin; j++)                {                    if(temp[start+j] > min[j])                    {                        goto loop;                    }                    if(temp[start+j] < min[j])                    {                        memcpy(min,temp + start,1500);                        lengmin = yxleng;                    }                }            }        }loop:        continue;    }    printf("The maximum value is : %s\n",max);    printf("The minimum value is : %s",min);    return 0;}
这是昨天调试了2个小时才AC的代码,问题处在loop跳出环节,之前一直用的是continue,以为continue能从头开始运行,后来才发现不是这样的,用loop直接跳到循环的末尾就好啦
0 0
原创粉丝点击