大整數的最大值最小值判斷

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 1500
int 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直接跳到循環的末尾就好啦
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章