阿里巴巴网站网络营销的平台,工信部网站备案要先做网站吗,北京网站改版公司,电脑做网页用什么软件文章目录 1.简单计算器2.获得月份天数3.HTTP状态码4. 图像相似度5.有序序列插入一个数 1.简单计算器
题目描述#xff1a;
KK实现一个简单计算器#xff0c;实现两个数的“加减乘除”运算#xff0c;用户从键盘输入算式“操作数1运算符操作数2”#xff0c;计算并输出表达… 文章目录 1.简单计算器2.获得月份天数3.HTTP状态码4. 图像相似度5.有序序列插入一个数 1.简单计算器
题目描述
KK实现一个简单计算器实现两个数的“加减乘除”运算用户从键盘输入算式“操作数1运算符操作数2”计算并输出表达式的值如果输入的运算符号不包括在、-、*、/范围内输出“Invalidoperation!”。当运算符为除法运算即“/”时。如果操作数2等于0.0则输出“Wrong!Division by zero!”
输入描述: 多组输入一行操作数1运算符操作数2其中运算符号包括四种、-、*、/。 输出描述: 针对每组输入输出为一行。如果操作数和运算符号均合法则输出一个表达式操作数1运算符操作数2运算结果各数小数点后均保留4位数和符号之间没有空格。如果输入的运算符号不包括在、-、*、/范围内输出“Invalid operation!”。当运算符为除法运算即“/”时。如果操作数2等于0.0则输出“Wrong!Division by zero!”。 输入: 1.03.0 1.0;4.0 44.0/0.0 输出: 1.00003.00004.0000 Invalid operation! Wrong!Division by zero! 参考代码
#include stdio.hint main()
{double x1 0;double x2 0;char ch 0;while (scanf(%lf%c%lf, x1, ch, x2) ! EOF){switch (ch){case :printf(%.4lf%c%.4lf%.4lf\n, x1, ch, x2, x1x2);break;case -:printf(%.4lf%c%.4lf%.4lf\n, x1, ch, x2, x1- x2);break;case *:printf(%.4lf%c%.4lf%.4lf\n, x1, ch, x2, x1 * x2);break;case /:if (x2 0.0){printf(Wrong!Division by zero!\n);break;}printf(%.4lf%c%.4lf%.4lf\n, x1, ch, x2, x1 / x2);break;default:printf(Invalid operation!\n);break;}}return 0;
}2.获得月份天数
题目描述:
KK想获得某年某月有多少天请帮他编程实现。输入年份和月份计算这一年这个月有多少天。
输入描述: 多组输入一行有两个整数分别表示年份和月份用空格分隔。 输出描述: 针对每组输入输出为一行一个整数表示这一年这个月有多少天。 输入: 2008 2 输出: 29 参考代码
#include stdio.hint main()
{int year 0;int month 0;int days[12] { 31,28,31,30,31,30,31,31,30,31,30,31};while (scanf(%d %d, year, month) ! EOF){int day days[month - 1];if (year % 4 0 year % 100 ! 0 || year % 400 0){if (month 2){day 1;}}printf(%d\n, day);}return 0;
}3.HTTP状态码
题目描述:
KK访问网站得到HTTP状态码但他不知道什么含义BoBo老师告诉他常见HTTP状态码
200OK请求已成功202Accepted服务器已接受请求但尚未处理。400Bad
Request请求参数有误403Forbidden被禁止404Not Found请求失败
500Internal Server Error服务器内部错误502Bad Gateway错误网关。
输入描述: 多组输入一行一个整数100~600表示HTTP状态码。 输出描述: 针对每组输入的HTTP状态输出该状态码对应的含义具体对应如下 200-OK 202-Accepted 400-Bad Request 403-Forbidden 404-Not Found 500-Internal Server Error 502-Bad Gateway 输入: 200 输出: OK 参考代码
#include stdio.hint main()
{int n 0;while (scanf(%d, n) ! EOF){switch (n){case 200:printf(OK\n);break;case 202:printf(Accepted\n);break;case 400:printf(Bad Request\n);break;case 403:printf(Forbidden\n);break;case 404:printf(Not Found\n);break;case 500:printf(Internal Server Error\n);break;case 502:printf(Bad Gateway\n);break;default:break;}}
}4. 图像相似度
题目描述:
给出两幅相同大小的黑白图像用0-1矩阵表示求它们的相似度。若两幅图像在相同位置上的像素 点颜色相同则称它们在该位置具有相同的像素点。两幅图像的相似度定义为相同像素点数占总像素点数的百分比。 输入描述: 第一行包含两个整数m和n表示图像的行数和列数用单个空格隔开。1≤m≤100, 1≤n≤100。之后m行每行n个整数0或1表示第一幅黑白图像上各像素点的颜色相邻两个数用单个空格隔开。之后m行每行n个整数0或1表示第二幅黑白图像上各像素点的颜色相邻两个数用单个空格隔开。 输出描述: 一个实数表示相似度(以百分比的形式给出)精确到小数点后两位。 输入
3 3
1 0 1
0 0 1
1 1 0
1 1 0
0 0 1
0 0 1 输出: 44.44 参考代码
#include stdio.hint main()
{int m 0;int n 0;int a[100][100] { 0 };int b[100][100] { 0 };float count 0.0;int i 0;int j 0;scanf(%d %d, m, n);for (i 0; i m; i){for (j 0; j n; j){scanf(%d, a[i][j]);}}for (i 0; i m; i){for (j 0; j n; j){scanf(%d, b[i][j]);}}for (i 0; i m; i){for (j 0; j n; j){if (a[i][j] b[i][j]){count;}}}printf(%.2f\n, 100.0 * count / (m*n));return 0;
}5.有序序列插入一个数
题目描述:
有一个有序数字序列从小到大排序将一个新输入的数插入到序列中保证插入新数后序列仍然是升序。
输入描述: 第一行输入一个整数(0≤N≤50)。第二行输入N个升序排列的整数输入用空格分隔的N个整数。第三行输入想要进行插入的一个整数。 输出描述: 输出为一行N1个有序排列的整数。 输入: 5 1 6 9 22 30 8 输出: 1 6 8 9 22 30 参考代码 #include stdio.hint main(){int n 0;int m 0;int arr[50] { 0 };int i 0;scanf(%d, n);for (i 0; i n; i){scanf(%d, arr[i]);}scanf(%d, m);for (i n; i 0; i--){if (arr[i-1] m){arr[i] arr[i - 1];}else{arr[i] m;break;}}if (i 0){arr[0] m;}for (i 0; i n 1; i){printf(%d , arr[i]);}return 0;}