CSP 2017-03

难道只能水前三题嘛QAQ…
随便写了一下前三题 1A
第四题写了一个基本的Dijkstra算法 不知道什么地方写错了 构造了一点样例也没有测出来
等我刷完水题再回来返工吧 mark一下

1.

#include

int main(){
    int number;
    int count_number,count;
    int n,k;
    while(~scanf("%d %d",&n,&k)){
        count = count_number = 0;
        while(n--){
            scanf("%d",&number);
            if(number + count >= k){
                count = 0;
                count_number++;
            }else count = count + number;
        }
        if(count != 0) count_number++;
        printf("%d\n",count_number);
    }
    return 0;
}

2.

#include

void move(int , int);

int local[1005];
int index[1005];

int main(){
    int i;
    int n,N;
    int p,q;
    while(~scanf("%d",&n)){
        for(i = 0; i < n; i++){
            local[i] = i+1;
            index[i+1] = i;
        }
        scanf("%d",&N);
        while(N--){
            scanf("%d %d",&p,&q);
            move(p,q);
        }
        printf("%d",local[0]);
        for(i = 1; i < n; i++) printf(" %d",local[i]);
        printf("\n");
    }
    return 0;
}

void move(int p, int q){
    int i;
    int localtion;
    localtion = index[p];
    if(q > 0){
        for(i = localtion; i < q + localtion; i++){
            local[i] = local[i+1];
            index[local[i]]--;
        }
        local[i] = p;
        index[p] = i;
    }else if(q < 0){
        for(i = localtion; i > localtion + q; i--){
            local[i] = local[i-1];
            index[local[i]]++;
        }
        local[i] = p;
        index[p] = i;
    }
}

3.

#include
#define BUF_SS 101

int judge_rows(int );

int index = 0;//index of buf_p
int judge1;
int judge2;
char buf[101];
char buf_p[101];

/* 
   type
   1:hang
   2:*
*/

int main(){
    int i;
    int type,count;
    int test;
    index = judge1 = judge2 = type = 0;
    while(fgets(buf, BUF_SS, stdin)){
        if(buf[0] == '\n'){
            if(type == 2){
                printf("\n");
            }else if(type == 1){
                printf("%s

\n"
,buf_p); } type = 0; index = 0; continue; } if(buf[0] == '#'){ for(count = 0; buf[count] == '#'; count++); printf("%d>",count); for(i = count; buf[i] == ' '; i++); test = judge_rows(i); buf_p[index] = '\0'; printf("%s%d>\n",buf_p,count); index = 0; continue; } if(buf[0] == '*'){ if(type == 0) printf("
    \n"); type = 2;//** for(i = 1; buf[i] == ' '; i++); printf("
  • "); test = judge_rows(i); buf_p[index] = '\0'; printf("%s
  • \n"
    ,buf_p); index = 0; continue; } if(type == 0){ buf_p[index++] = '<'; buf_p[index++] = 'p'; buf_p[index++] = '>'; }else{ printf("%s\n",buf_p); index = 0; } test = judge_rows(0); buf_p[index] = '\0'; type = 1; } if(type != 0){ if(type == 2){ printf("
\n"
); }else if(type == 1){ printf("%s

\n"
,buf_p); } } return 0; } int judge_rows(int count){ int i,j; for(i = count; buf[i] != '\n'; i++){ if(buf[i] == '_'){ if(judge1 == 1){ judge1 = 0; return i; } buf_p[index++] = '<'; buf_p[index++] = 'e'; buf_p[index++] = 'm'; buf_p[index++] = '>'; judge1 = 1; i = judge_rows(i+1); buf_p[index++] = '<'; buf_p[index++] = '/'; buf_p[index++] = 'e'; buf_p[index++] = 'm'; buf_p[index++] = '>'; }else if(buf[i] == '['){ for(j = i+1; buf[j] != '('; j++); buf_p[index++] = '<'; buf_p[index++] = 'a'; buf_p[index++] = ' '; buf_p[index++] = 'h'; buf_p[index++] = 'r'; buf_p[index++] = 'e'; buf_p[index++] = 'f'; buf_p[index++] = '='; buf_p[index++] = '"'; j = judge_rows(j+1); buf_p[index++] = '"'; buf_p[index++] = '>'; i = judge_rows(i+1); buf_p[index++] = '<'; buf_p[index++] = '/'; buf_p[index++] = 'a'; buf_p[index++] = '>'; i = j; }else if(buf[i] == ')') return i; else if(buf[i] == ']') return i; else buf_p[index++] = buf[i]; } }

Emmmm..
打卡打卡…
虽然是大水怪 但还要继续努力啊

你可能感兴趣的:(CSP考前训练)