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

📄 1016.c

📁 pku online judge的一些题目的代码,全部AC的,适合编程初学者以及爱好者
💻 C
字号:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int cmp( const void *a , const void *b ) 
{ 
	return *(char *)a - *(char *)b; 
} 
int main()
{
	char s[81],a[81],b[30][81];
	int i,j,k,m,count,time;
	while(scanf("%s",s),strcmp(s,"-1"))
	{
		time=0;
		while(1)
		{
			for(k=0;k<time;k++)
				if(strcmp(s,b[k])==0)
					break;
			if(k<time)
				break;
			strcpy(b[time],s);
			m=strlen(s);
			qsort(s,m,sizeof(s[0]),cmp);
			for(i=j=0,count=1;i<m;i++)
				if(s[i]==s[i+1])
					count++;
				else
				{
					if(count>9)
					{
						a[j++]=count/10+'0';
						a[j++]=count%10+'0';
						a[j++]=s[i];
					}
					else
					{
						a[j++]=count+'0';
						a[j++]=s[i];
					}
					count=1;
				}
			a[j]='\0';
			if(strcmp(b[time],a))
			{
				strcpy(s,a);
				time++;
				if(time==16)
					break;
			}
			else
				break;
		}
		if(time==16)
			printf("%s can not be classified after 15 iterations\n",b[0]);
		else if(k<time)
			printf("%s enters an inventory loop of length %d\n",b[0],time-k);
		else if(time==0)
			printf("%s is self-inventorying\n",b[0]);
		else
			printf("%s is self-inventorying after %d steps\n",b[0],time);
	}
	return 0;
}

⌨️ 快捷键说明

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