美文网首页
无C不欢

无C不欢

作者: amulil | 来源:发表于2015-05-09 13:56 被阅读57次

    <h4>2015 5.9 星期六 晴</h4>
    <p>Function:将多个空格用一个空格替代</p>
    <pre>
    int c,flag; //The answer of me
    while((c = getchar()) != EOF) {
    if(c != ' ')
    if(flag == 0)
    putchar(c);
    else {
    putchar(c);
    flag = 0;
    }
    if( c == ' ')
    if(flag == 0) {
    putchar(c);
    flag = 1;
    }
    }
    </pre>
    <pre>
    int c,lastc; //The answer of answer
    while((c = getchar()) != EOF) {
    if(c != ' ')
    putchar(c);
    if( c == ' ')
    if(lastc != ' ') // else if(lastc != ' ')
    putchar(c);
    lastc = c;
    }
    </pre>
    <p>Function: 换行输出单词</p>
    <pre>
    int c,lastc,state;
    state = OUT;
    while((c = getchar()) != EOF) {
    if(c == ' ' || c == '\t' || c == '\n') {
    if(state == IN){
    putchar('\n');
    state = OUT;
    }
    }
    else if(state == IN)
    putchar(c);
    else if(state == OUT) {
    putchar(c);
    state = IN;
    }
    }
    </pre>
    <pre>
    int c,lastc,state;
    state = OUT;
    while((c = getchar()) != EOF) {
    if(c == ' ' || c == '\t' || c == '\n') {
    if(state == IN){
    putchar('\n');
    state = OUT;
    }
    }
    else if(state == OUT) {
    putchar(c);
    state = IN;
    }
    else
    putchar(c);
    }
    </pre>
    <h4>2015 5.13 星期三 晴</h4>
    <p>Function: quick sort</p>
    <pre>

    include<stdio.h>

    include<string.h>

    define MAX 1000

    int qsor[1000];
    int main()
    {
    int T,n;
    void qsort(int [], int, int);
    scanf("%d",&T);
    while(T > 0)
    {
    int i;
    scanf("%d",&n);
    memset(qsor, 0, sizeof(qsor));
    for(i = 0;i<n;i++){
    scanf("%d", &qsor[i]);
    }
    qsort(qsor, 0, n-1);
    for(i = 0;i<n;i++){
    printf("%d ", qsor[i]);
    }
    printf("\n");
    T--;
    }
    }
    </pre>
    <pre>
    void qsort(int v[], int left, int right) {
    int i,last;
    void swap(int [], int, int);
    if(left <= right)
    return;
    swap(v, left, (left + right)/2);
    last = left;
    for(i = left + 1; i <= right; i++)
    if(v[i] < v[left])
    swap(v, ++last, i);
    swap(v, last, left);
    qsort(v, left, last-1);
    qsort(v, last+1, right);
    }
    void swap(int v[], int i, int j) {
    int temp;

    temp = v[i];
    v[i] = v[j];
    v[j] = temp;
    

    }
    </pre>

    相关文章

      网友评论

          本文标题:无C不欢

          本文链接:https://www.haomeiwen.com/subject/gbigfttx.html