⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1670.cpp

📁 这是哈尔滨工业大学acmOJ的源代码
💻 CPP
字号:
/*  This Code is Submitted by wywcgs for Problem 1670 on 2005-10-30 at 01:31:21 */ 
#include <cstdio>

const int MAX = 512;

void printSeq(char*, int);

int main()
{
	char line[MAX], stack[MAX];
	int i;
	int n, top;
	
	while(gets(line) != NULL) {
		n = top = 0;
		for(i = 0; line[i] != 0; i++) {
			if(top == 0) {
				stack[top++] = line[i];
				n++;
			} else if(line[i] == stack[top-1]) {
				if(top == 1) {
					n++;
				} else {
					printSeq(stack, top-1);
					top = 0;
					stack[top++] = line[i];
					n = 2;
				}
				if(n == 9) {
					printf("9%c", stack[--top]);
					n = 0;
				}
			} else {
				if(top == 1 && n != 1) {
					printf("%d%c", n, stack[--top]);
					n = 0;
				}
				stack[top++] = line[i];
				n = 1;
			}
		}
		if(top == 1 && n != 1) {
			printf("%d%c", n, stack[--top]);
		} else {
			printSeq(stack, top);
		}
		putchar('\n');
	}
	
	return 0;
}

void printSeq(char *p, int n)
{
	int i;
	if(n > 0) {
		putchar('1');
		for(i = 0; i < n; i++) {
			putchar(p[i]);
			if(p[i] == '1') {
				putchar(p[i]);
			}
		}
		putchar('1');
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -