惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
Y
Y Combinator Blog
Recorded Future
Recorded Future
博客园 - Franky
I
InfoQ
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Cloudbric
Cloudbric
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Check Point Blog
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
U
Unit 42
N
Netflix TechBlog - Medium
The Cloudflare Blog
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
T
Troy Hunt's Blog
Engineering at Meta
Engineering at Meta
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
B
Blog
S
Securelist
H
Hacker News: Front Page
Google Online Security Blog
Google Online Security Blog
G
Google Developers Blog

博客园 - DonePuzzle

读红楼梦 听完一曲琵琶语 大学图书馆的感觉 继续写博 威海夜雨 做上机题 博文阅读密码验证 - 博客园 复试上机题 在线播放flv 我们看海去 学习PetShop 博文阅读密码验证 - 博客园 递归下降分析程序构造 apache实现多个端口 君子抉(4月28日) 继续君子抉 忙里偷闲4.22 君子抉第三天(4月20日) 君子抉第二天(4月19日)
复试题之我的解答
DonePuzzle · 2009-03-15 · via 博客园 - DonePuzzle

Problems A.请写一个程序,判断给定整数序列能否构成等差数列
输入说明:多组数据,每组输入数据由两行构成,第一行只有一个整数n(<1000),表示序列长度(即序列中整数的个数,0表示输入结束),第二行为n个整数,每个整数的取值区间都为[-32768----32767],整数之间以空格或挑格间隔。
输出说明:对于每一组数据,输出一个yes或no,表示该序列能否构成等差数列。
输入样本:
6
23 15 4 18 35 11
3
3 1 2
0
输出样本:
yes
no

 1 #include <cstdlib>
 2 #include <iostream>
 3 #include <vector>
 4 #include <String>
 5 using namespace std;
 6 int  check(int* pa,int n)
 7 {
 8         if(n==2||n==1)
 9         return 1;
10         else if(n>2)
11         {
12              for(int i=1;i<n-1;i++)
13                 if(pa[i]*2!=(pa[i-1]+pa[i+1]))
14                     return 0;
15          }
16         return 1;        
17 }
18 int main(int argc, char *argv[])
19 {
20     vector<int> vt;
21     int n=1;
22    while(true)
23    {
24     cin>>n;
25     if(n==0
26         break;
27         else{
28                int *pa=new int[n];
29                for(int i=0;i<n;i++)
30                   cin>>pa[i];
31                 vt.push_back(check(pa,n));
32             }
33            
34     }
35     for(int j=0;j<vt.size();j++)
36             {
37             if(vt[j]==1)
38                    cout<<"yes\n" ;
39             else
40                    cout<<"no\n";
41             }
42     //cout<<"asf"<<endl;
43     system("PAUSE");
44     return EXIT_SUCCESS;
45 }
46