期末编程测试(Week 12)

Quiz1 判断闰年

#include <iostream>
using namespace std;
int main()
{
int year;
cin >> year; if(year % 100 == 0 && year % 400 != 0 || year % 4 != 0 || year % 3200 == 0)
cout<<'N'<<endl;
else cout<<'Y'<<endl; return 0;
}

Quiz2 能被3,5,7整除的数

#include <iostream>
using namespace std;
int main()
{
int n; while(cin >> n)
{
if (n % 3 == 0)
cout << '3' << ' ';
if (n % 5 == 0)
cout << '5' << ' ';
if (n % 7 == 0)
cout << '7' << ' ';
if (n % 3 != 0 && n % 5 != 0 && n % 7 != 0)
cout << 'n' << ' ';
cout<<'\n';
} return 0;
}

Quiz3 最远距离

#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{
int n;
cin >> n; const int N = n;
double one[N],two[N];
double maxDistance = 0.0;
for (int i = 0; i < N; i++) {
cin>>one[i]>>two[i];
} for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
double distance = sqrt((one[i]-one[j])*(one[i]-one[j])+(two[i]-two[j])*(two[i]-two[j]));
if(distance > maxDistance)
maxDistance = distance;
}
} cout << fixed << setprecision(4) <<maxDistance<<endl;
return 0;
}

Quiz4 简单计算器

#include <iostream>
using namespace std;
int main()
{
int a,b;
char c;
cin>>a>>b>>c;
if(c == '/' && b == 0)
{
cout<<"Divided by zero!"<<endl;
} if(c!='/' && c!='+' && c!='-' && c!='*')
{
cout<<"Invalid operator!"<<endl;
} if(c == '+')
{
cout<<a+b<<endl;
}
if(c == '-')
{
cout<<a-b<<endl;
}
if(c == '*')
{
cout<<a*b<<endl;
}
if(c == '/')
{
cout<<a/b<<endl;
}
return 0;
}

Quiz5 字符串插入

#include<cstdio>
#include<string>
#include<iostream>
using namespace std; int main()
{
string str,substr;
while(cin>>str)
{ cin>>substr; char temp1,temp2,temp;
int len1,len2,max;
len1=str.length();
len2=substr.length(); max=0;
for(int i=1;i<len1;i++)
{
temp1 = str[max];
temp2 = str[i];
if(temp1<temp2)
max=i; }
temp=max+1;
str.insert(temp,substr);
cout<<str<<endl;
}
return 0;
}

最新文章

  1. SQL Server数据库性能优化之索引篇【转】
  2. Ueditor 编译发布后无法使用上传图片、附件等功能
  3. 调用newtonsoft.json反序列出错
  4. mac 系统通用快捷键(mac 下的应用多数会往这些标准看齐)(转:http://yang3wei.github.io/blog/2013/02/08/chen-ni-yu-mac-chen-ni-yu-xcode/)
  5. ipcs命令
  6. Entity Framework 教程
  7. ios 实现推送消息
  8. Duilib中Webbrowser事件完善使其支持判断页面加载完毕
  9. SVN 忽略获取和提交obj、bin文件夹
  10. Ubuntu 15.04 配置VPN的方法详解
  11. HDURevenge of Segment Tree(第二长的递增子序列)
  12. php引用传值详解
  13. Android视频录制从不入门到入门系列教程(二)————显示视频图像
  14. 2018-2019-2 20175306实验二面向对象程序设计《Java开发环境的熟悉》实验报告
  15. orcale mysql基本的分页查询法
  16. 如何使用onclick方式添加多个事件回调函数
  17. 强迫症犯了,忍不住赞一下slf4j包Logger.java的优雅代码
  18. [UE4]让子弹产生伤害
  19. day01-Python输出
  20. 04_web基础(六)之请求转发与重定向

热门文章

  1. N皇后问题 回溯非递归算法 C++实现2
  2. Python中关于第三方库的补充
  3. C#栈、堆的理解(2)
  4. TensorFlow命令行参数FLAGS使用
  5. 关于小程序中textarea内的字体浮动问题
  6. WANNACRY病毒中的加密技术分析
  7. Android xUtils3.0使用手册(一)- 基础功能使用
  8. 2 个案例带你迅速入门 Python Flask 框架
  9. hdu_1052 Tian Ji -- The Horse Racing 贪心
  10. 【JAVA基础】02 Java基础语法