20160131.CCPP體系詳解(0010天)

尹成發表於2016-02-16

程式片段(01):Test.c+NewTest.c
內容概要:題目測試

///Test.c

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define r char S; T R; I N, G, s
#define A(P,O) for(P=O; *P; P=U(P))
typedef char T[128], *I, p[2400];
#define memset  (I)\
    memset
void*P = strcpy; I Q(); typedef const void*f; int u(f P, f O){
    return strncmp((I)P, (I)O, 1);
} T g, c = { 127 }; char l, F[6000000]; I U(I P){
    r; strncpy(R, P, 2);
    s = strchr(
        strcpy(P, c), 0)
        ; strncpy(P, R, 2); return s;
} T q, B, E; I t(I P){
    r; qsort(P,
        strlen(P), 1, u);
    if (s = strstr(P, c))*s = 0; return P;
} T a = { 2 }; void D(){
    r;
    S = 1; strcpy(R, c); t(F);
    for (; memset(E, S, l),
        (S = strlen(
        strcat(R, c))) < *R; t(s))for (s = B;
    N = strstr(F, E); s = F)
        * memset(N, *c, l) = S;
} p H = "(*&,.", k; I j(I P){
    r = (I)malloc(
        strlen(
        strcat(P, "\177 ")));
    *strstr(P, c) = 0;
    return strcpy(s, P);
} int K(f P, f O){ return u(O, P); } void
b(){
    qsort(F,
        strlen(F), 1, K);
} void n(I P){
    r; A(P, P){
        if (N = strchr(F, *P)); else{
            t(F);
            b(); memset(B, l, *F); N = F;
            while (*strrchr(B, l) = 0,
                *P <= (S = strlen(B))){
                *memset(E, S, l)
                    = *c; strcat(F, E);
            } memset(B, 0, S);
        } *N = *c;
    } D();
} void C(I P, I O){
    r; A(P, P)A(s, O){
        *strrchr(
            memset(
            strchr(
            memset(
            strncpy(k, B, 254), l, *P), 0), l, *s), l) = 0;
        *q = strlen(k)
            ; strcat(F, q);
    } D();
} T i = "\13<\f="; void o(I P){
    A(P, P){
        *strrchr(
            memset(B, *c, *P), *c)
            = 0; memset(B, 0,
            *P = strlen(B));
    }
} int V(f P, f O){ return u(*(I*)P, *(I*)O); } void e(I O){
    r; strcpy(H, O)
        ; strcpy(R, c); for (;
    0 < strncmp(F, H, 1)
        ; strcat(R, c))A(s,
        H) memset(B, 0,
        *s = strlen(
        strcat(
        memset(B, *c, *s), c))); *k = 0; do{
        while
            (0 <= strcmp(F, H)){
            n(H); b();
            *q = strlen(R)
                ; strcat(k, q);
        }
        *strrchr(R, *c) = *B; o(H);
    } while (*R);
} char d(I P){
    if (P = strstr(P, g)){
        if ((*g = getchar()) < *i)' ' < *g ? o(g) : d(" ");
    }
    else P = B; return*P;
} I m(I
    P){
    qsort(P,
        strlen(P), 1, K); return*P == *c ? U(P) : P;
} void J(I P){
    r = m(P);
    if (P < s) putchar('-')
        ; memset(B, l, *s); do{
        *E = *i;
        if (N = strchr(s,
            *q = strlen(B)))
            t(memset(
            memcpy(E, i, l), *c,
            strspn(N, q)))
            ; putchar(*E);
        *strrchr(B, *B = l) = 0;
    } while
        (*B); puts(B)
        ; free(P);
} I M(){
    r = Q(), P, O; while (S = d(".)$")){
        N = Q();
        G = strcpy(F, B); P = m(s); O = m(N); if (S == ')'){ C(P, O); }
        else{
            strcpy(F, P); e(O); if (S == '.')G = k; else O = N;
        } free(s); G = j(G);
        s = strcat(G, P == s == (O == N) ? B : c)
            ; free(N);
    } return s;
} I h(){
    r, P, O; for (N = M(); S = d("*,");
    N = strcat(s, S ? c : B)){
        G = M(); P = m(N); O = m(G); S = O == G == (S == ','); if (P == N == S)
        if (strcmp(P, O) < 0)
        {
            strcpy(F, O); n(P);
        }
        else{ strcpy(F, P); n(O); S = N < P; }
        else{
            strcat(
                strcpy(F, P), O); D();
        }
        s = j(F); free(N)
            ; free(G);
    } return N;
} I Q(){
    r; if (S = d(","))
    if (N = strstr(s = Q(), c))*N = *B;
    else strcat(s, c); else if (d("'")){ s = h(); S = d("("); }
    else{
        strcpy(F, B); while (*q = d(i))
        {
            strcpy(H, F)
                ; memset(
                strncpy(F, B, l), S = 1,
                strcspn(i, q)); C(H, a);
        } s = j(F);
    } if (!S){
        o(strcpy(F, "tzouby!fssps"))
            ; puts(F);
    } return s;
} int main1(int P, I*O)
{
    qsort(O, P, sizeof*O, V);
    l = 1 < P ? strtol(*O, 0, l) : 10; C(H,
        i); strcpy(i, F); d(g); while (!d("\377"))for (J(h()); !d("\377\n"); d(g)); return 0;
}
///NewTest.c
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h >


void main123()
{
    /*int x, y;
    if (x < y)scanf("%d", &x); else scanf("%d", &y);*/
    //int i;
    //while (!scanf("%d", &i))  //!1
    //  getchar();


    //abcde<回車>

    ////ch = getchar()  //'a'
    //char ch;
    //                                  //a ,b ,c d, e
    //while ((ch = getchar()) == 'e')  //e e e
    //{
    //  putchar(ch);


    //  printf(" * ");
    //}
    //int x = 5, a = 0, b = 0;
    //if (x != (a + b)) printf("x=5\n");
    //else printf("a=b=0\n");
    //r  ight   ?
    //jhiu
    //char c;
    //c = getchar();

    //while ((c = getchar()) != '?')
    //  putchar(++c);

    //int a, b, c, d, x;
    //a = c = 0;
    ////b = 1; d = 20;
    ////if (a)
    ////    d = d - 10;
    ////else if (!b)  //else if  (if else配對)
    ////    if (!c)x = 15;
    ////    else x = 25;

    //  switch (a)
    //  {
    //  case 2:
    //      break;

    //  }
    //
    //int  a = 10;
    //int b = 20;
    //switch (1+a+b)
    //{
    //case 1:
    //  break;
    //}
    //int n[2] = { 0 }, i, j, k = 2;
    //for (i = 0; i < k; i++)
    //for (j = 0; j < k; j++) n[j] = n[i] + 1;

    //printf("%d\n", n[k]);//n[2]
    //int i = 1, j = 1, k = 2;
    //j++ || ((k++) &&(i++));//短路效應

    ////1 + 3 * 4;
    //
    //printf("%d,%d,%d\n", i, j, k);
    //int a=10;
    //int c = 0;
    //switch (a)
    //{
    //case 2:
    //  ;
    //}

    /*double sum = 0.0, x;
    for (x = 0.0; x < 3.0; x += 0.1)
    sum += x,printf("\n%f",x);


    printf("\n x=%f", x);*/

    //int a = 1; 
    //int b = 10;
    //do
    //{
    //  b -= a;    //b=9,a=2   //b=6,a=3  //b=2,a=4  // b=-3  a=5
    //  a++;

    //} while (b-- < 10);
    //printf("a=%d,b=%d", a, b);
    //system("pause");


        int i, j, k;
        for (i = 1; i <= 6; i++)
        {
            for (j = 1; j <= 20 - 2 * i; j++)
                printf(" ");
            for (k = 1; k <= i; k++)
                printf("%4d", i);
            printf("\n");
        }
        system("pause");
}

void main124()
{
    char c;
    c = getchar();
    //switch必須快語
    switch (c)
    {
    case 0:case 1: printf("%d", c - '0'); break;
    default:putchar(c);
    }



}

void main125()
{
    int a, b; char op;

        scanf("%d%d", &a, &b);

        scanf("%c", &op);
    switch (op)
    {
    case '+':  printf("%d + %d = %d\n", a, b, a + b); break;
    case '-':  printf("%d - %d = %d\n", a, b, a - b); break;
        default:printf(""); exit(1);
    }
}

void main126()
{
    int n, i = 1;  long sum = 0;
    printf("輸入一個正整數:");
    scanf("%d", &n);
    while (i < n)
        i += 2;
    sum += i;
    if (n % 2 == 0)   n--;
    printf("輸出1+3+5+…+%d=%1d\n", n, sum);

    system("pause");
}

void main1215()
{
    int s, t, a, b;
    scanf("%d,%d", &a, &b);
    //a=5//b=2
    s = 1;
    t = 1;
    if (a > 0) //作用範圍最近的;如果整體的ifelse會巢狀
    {
        s = s + 1;         /* ① */// s=2

        if (a > b)
        {
            t = s + t;          /* ② */
        }
        else if (a == b)
        {
            t = 5;
        }
        else
            t = 2 * s;
    }


    printf("s=%d,t=%d\n", s, t);
    system("pause");
}


void  main127()
{

        int a, b, m, n;
        scanf("%d%d,\n", &a, &b);//a=1,b=0
        m = 1; n = 1;
        if (a > 0)
        {
            m = m + n; //1>0  m=2,n=1
            if (a < b)
                n = 2 * m;
            else if (a == b)
                n = 5;
            else
                n = m + 1;

        }

        printf("m=%d n=%d\n", m, n); //1,2


        system("pause");
}

void main128()
{

        int s, t, a, b;
        scanf("%d,%d", &a, &b);//a=5//b=2
        s = 1;
        t = 1;

        //if作用範圍只有一句大括號
        if (a > 0)
            s = s + 1;         /* ① */

        if (a > b) 
            t = s + t;          /* ② */
        else if (a == b) 
            t = 5;
        else
            t = 2 * s;


        printf("s=%d,t=%d\n", s, t);

        system("pause");
}
void main234()
{
    int a, b, m, n;
    scanf("%d%d,\n", &a, &b);//a=1,b=0
    m = 1; n = 1;
    if (a > 0)
        m = m + n; //1>0  m=2,n=1

    //配對就近
    if (a < b)
        n = 2 * m;
    else if (a == b)
        n = 5;
    else
        n = m + 1;

    printf("m=%d n=%d\n", m, n); //1,2
}

程式片段(02):遞迴.c
內容概要:轉化遞迴

#include <stdio.h>
#include <stdlib.h>

//01.編寫程式,求a+aa+aaa+...(n個)aaa,其中a是一個數字.例如:3+33+333+3333+33333.
//  1.分析問題步驟:
//      (1).複雜問題簡單化
//      (2).複雜問題規律化
//      (3).複雜問題重複化
//      
//  2.遞迴所能解決的問題:
//      重複問題
//      遞推關係
//   關係一:
//      1--->3
//      2--->33
//      3--->333
//      n--->(n個)3-->((n-1)個)3*10+3
int nAN(int num, int ele)
{
    if (1 == num)
        return ele;
    return nAN(num - 1, ele) * 10 + ele;
}

//   關係二:
//      1-->3
//      2-->3+33
//      3-->3+33+333
//      n-->n個整數,n個元素組成最大的數
//      Sn-->Sn-1+an
int qNH(int num, int ele)
{
    if (1 == num)
        return ele;
    return qNH(num - 1, ele) + nAN(num, ele);
}



int main(void)
{
    //printf("%d \n", nAN(5, 3));

    //printf("%d \n", qNH(4, 1));

    system("pause");
}

//void digui3(int n, int a, int sum, int an)
//{
//  if (n == 0)
//  {
//      printf("%d\n", sum);
//      return;
//  }
//  else
//  {
//      an = an * 10;
//      an += a;
//      sum += an;
//      digui3(n - 1, a, sum, an);
//  }
//}

相關文章