#11123: 為何得到Killed?(中止訊號)


vagrantlike (丫維)

學校 : 不指定學校
編號 : 27614
來源 : [114.24.87.102]
最後登入時間 :
2020-01-23 17:45:52
d574. 節約符咒 -- jack1 | From: [163.29.253.105] | 發表日期 : 2016-07-04 15:04

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

char original_string[10000001];
int group_num[2][10000001];


int main() {
    int n =0, temp_n =0,i = 0,temp_i = 0,j = 0,reduced_n = 0;

    while(scanf("%d",&n)==1) {
        temp_n = n;
        i = 0,j = 0,temp_i=0;

        scanf("%s",original_string);

        for(i = 0; i<temp_n; ++i) {

            while((j<temp_n-1)&&(original_string[j]==original_string[j+1])) {
                ++j;
            }
         
            group_num[0][i]=j;
            group_num[1][i]=original_string[j];

            if(j==temp_n) {
                break;
            }

            temp_i = i;
            ++j;

        }


        reduced_n = (temp_i+1)*2;

        if(reduced_n>=n) {
            printf("%s\n",original_string);
        } else {
            printf("%d%c",group_num[0][0]+1,group_num[1][0]);

            for(i = 1; group_num[1][i]!='\0'; ++i) {
                printf("%d%c",group_num[0][i]-group_num[0][i-1],group_num[1][i]);
            }

            printf("\n");
        }
    }

    return 0;
}

 
ZeroJudge Forum