Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for n days in a row. Each of those n days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that he has found extra-terrestrial intelligence if there is a system in the way the signals has been received, i.e. if all the intervals between successive signals are equal. Otherwise, Vasya thinks that the signals were sent by some stupid aliens no one cares about. Help Vasya to deduce from the information given by the receiver if he has found extra-terrestrial intelligence or not.
Input
The first line contains integer n (3 ≤ n ≤ 100) — amount of days during which Vasya checked if there were any signals. The second line contains n characters 1 or 0 — the record Vasya kept each of those n days. It’s guaranteed that the given record sequence contains at least three 1s.
Output
If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO.
Example
Input
8
00111000
Output
YES
Input
7
1001011
Output
NO
Input
7
1010100
Output
YES
题意:检查1之间的间距是否相等。、
注意文件的读入写出
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
using namespace std;
int cnt[1000];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n;
scanf("%d",&n);
string s;
cin>>s;
int num=0;
for(int i=0;i<s.length();i++){
if(s[i]=='1'){
cnt[++num]=i;
}
}
int k=cnt[2]-cnt[1];
int i;
for(i=2;i<num;i++){
if(cnt[i+1]-cnt[i]!=k){
break;
}
}
if(i==num){
printf("YES\n");
}else{
printf("NO\n");
}
return 0;
}
本文介绍了一种通过分析接收到的信号来判断是否存在规律性的外星信号分析算法。该算法记录了连续多天的信号接收情况,并通过检测1之间的间隔是否一致来判断信号是否来自智能生命。
692

被折叠的 条评论
为什么被折叠?



