zoukankan      html  css  js  c++  java
  • uva120 Stacks of Flapjacks

    郁闷

    View Code
    #include<stdio.h>
    #include<stdlib.h>
    int cmp(const void *a,const void *b)
    {
        return *(int *)a - *(int *)b;
    }
    int main()
    {
        int a[102] = {0}, b[102], top = 0;
        int i, j, k, flag, t;
        char ch;
        while((ch = getchar()) != EOF)
        {
            if(ch == ' ')
            {
                top++;
            }
            else if (ch >='1' && ch <= '9')
            {
                if(a[top] != 0)
                {
                    a[top] = a[top]*10+ch-'0';
                }
                else
                    a[top] = ch-'0';
                b[top] = a[top];
            }
            else
            {
                for(i = 0;i < top; i++)
                    printf("%d ",a[i]);
                printf("%d\n",a[top]);
                top++;
                qsort(b,top,sizeof(b[0]),cmp);
                flag = top-1;
                for(i = top-1;i >= 0; i--)
                {
                    if(a[i] != b[i])
                    {
                        for(j = 0;j <= i; j++)
                            if(a[j] == b[i])
                                break;
                        if(j != 0)
                        {
                            printf("%d ",top-j);
                            for(k = 0;k < j; k++,j--)
                            {
                                t = a[k];
                                a[k] = a[j];
                                a[j] = t;
                            }
                            printf("%d ",top-i);
                            for(k = 0;k <= i/2; k++)
                            {
                                t = a[k];
                                a[k] = a[i-k];
                                a[i-k] = t;
                            }
                        }
                        else
                        {
                            printf("%d ",top-i);
                            for(k = 0;k <= i/2; k++)
                            {
                                t = a[k];
                                a[k] = a[i-k];
                                a[i-k] = t;
                            }
                        }
                    }
                }
                printf("0\n");
                top = 0;
                memset(a,0,sizeof(a));
            }
        }
        return 0;
    }
  • 相关阅读:
    数据快照
    2.21毕设进度
    2.20毕设进度
    Java读取文件,明明文件存在,却报错文件找不到
    2.19毕设进度
    2.18毕设进度
    2.17毕设进度
    2.16毕设进度
    2.15毕设进度
    2.14毕设进度
  • 原文地址:https://www.cnblogs.com/SDUTYST/p/2593715.html
Copyright © 2011-2022 走看看