The 2011 Rocky Mountain Regional Contest&&Iterated Difference

水题~~~

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<cmath>
#include<algorithm>
using namespace std;
int s[21];
int n;
bool judge()
{  
	for(int i=0;i<n-1;++i)
		if(s[i]!=s[i+1]) return false;
	return true;
   
}
void Change()
{
	for(int i=0;i<n;++i)
		s[i]=abs(s[i]-s[i+1]);
	    s[n]=s[0];
}
int main()
{    int T=0;
	while(scanf("%d",&n)!=EOF,n)
	{  
		T++;
	  for(int i=0;i<n;++i)
			scanf("%d",&s[i]);
		  s[n]=s[0];
		  int ans=0;
		  bool flag(false);
		   while(ans<=1000&&!flag)
		   {   Change();
		       if(!judge()) ans++;
			   else flag=true;
		   }
		   if(flag)  printf("Case %d: %d iterations\n",T,ans);
		   else      printf("Case %d: not attained\n",T);
	}return 0;
}


你可能感兴趣的:(The 2011 Rocky Mountain Regional Contest&&Iterated Difference)