当前位置: 首页 > news >正文

佛山外贸网站建设新闻外贸seo网站推广公司

佛山外贸网站建设新闻,外贸seo网站推广公司,05网课时作业本答案,h5手机制作网站开发OJ题⽬输⼊情况汇总 单组测试用例:程序运行一次,只处理一组数据多组测试用例:程序运行一次,会处理多组数据 测试数据组数已知(输入)测试数据组数未知特殊值结束测试数据 单组测试⽤例 B2009 计算 (ab)/c 的值 - 洛谷 #includ…

OJ题⽬输⼊情况汇总

  • 单组测试用例:程序运行一次,只处理一组数据
  • 多组测试用例:程序运行一次,会处理多组数据
    • 测试数据组数已知(输入)
    • 测试数据组数未知
    • 特殊值结束测试数据

单组测试⽤例

B2009 计算 (a+b)/c 的值 - 洛谷
#include <bits/stdc++.h>
using namespace std;int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);int a, b, c;cin >> a >> b >> c;cout << (a + b) / c << endl;return 0;
}
B2081 与 7 无关的数 - 洛谷
#include <bits/stdc++.h>
using namespace std;int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);int n;cin >> n;int sum = 0;for (int i = 1; i <= n; i++){if ((i % 7 != 0) && (i % 10 != 7) && (i / 10 != 7)){sum += i * i;}}cout << sum << endl;return 0;
}

多组测试用例

测试数据组数已知

多组输入a+b
#include <bits/stdc++.h>
using namespace std;int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);int n;cin >> n;int a, b;while (n--){cin >> a >> b;cout << a + b << endl;}return 0;
}
B2064 斐波那契数列 - 洛谷

![[Pasted image 20250308165752.png]]

#include <iostream>
using namespace std;int n;int main()
{cin >> n;int a = 0;while (n--){cin >> a;int i = 1, j = 1, k = 1;while (a >= 3){k = i + j;i = j;j = k;a--;}cout << k << endl;}return 0;
}
#include <bits/stdc++.h>
using namespace std;const int N = 40;
int a[N] = {0, 1, 1};int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);int i = 0;for (i = 3; i <= 30; i++){a[i] = a[i-1] + a[i-2];        }int n;cin >> n;int k;while (n--){cin >> k;cout << a[k] << endl;}return 0;
}
B3769 [语言月赛202305] 制糊串 - 洛谷
#include <bits/stdc++.h>
using namespace std;int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);string s, t;cin >> s >> t;int q;cin >> q;int l1, r1, l2, r2;while (q--){cin >> l1 >> r1 >> l2 >> r2;string s1 = s.substr(l1 - 1, r1 - l1 + 1);string t1 = t.substr(l2 - 1, r2 - l2 + 1);if (s1 < t1)cout << "yifusuyi" <<endl;else if (s1 > t1)cout << "erfusuer" << endl;elsecout << "ovo" << endl;}return 0;
}

题⽬中说"有q次询问",意思是程序要处理q组测试数据,(也就是对应 q 次循环),我们
要针对每次询问,给出⼀个结果。
其实就是之前的单组测试变成了 q 组测试,在之前的代码上套⼀层 while 循环即可。当有 q 次询问的时候, while(q–) 是⾮常⽅便的⽅式。然后就按照单组输⼊的⽅式处理每组输⼊的数据就好了。

测试数据组数未知

多组输入a+b 2
#include <bits/stdc++.h>
using namespace std;int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);int a, b;while (cin >> a >> b){cout << a + b << endl;}return 0;
}

cin >> a; 会返回⼀个流对象的引⽤,即 cin 本⾝。在C++中,流对象 cin 可以被⽤作布尔值来检查流的状态。如果流的状态良好(即没有发⽣错误),流对象的布尔值为true 。如果发⽣错误(如遇到输⼊结束符或类型不匹配),布尔值为 false 。
在 while (cin >> a >> b) 语句中,循环的条件部分检查 cin 流的状态。如果流成功读取到2个值, cin >> a >> b 返回的流对象 cin 将被转换为 true ,循环将继续。如果读取失败(例如遇到输⼊结束符或⽆法读取到2个值), cin >> a >> b 返回的流对象 cin 将被转换为 false ,循环将停⽌。

数字三角形
#include <bits/stdc++.h>
using namespace std;int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);int n;while (cin >> n){for (int i = 1; i <= n; i++){for (int j = 1; j <= i; j++){cout << j << " ";}cout << endl;}}return 0;
}
定位查找
#include <bits/stdc++.h>
using namespace std;int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);int n;int a;while (cin >> n){vector<int> s(n);for (auto &x : s){cin >> x;}cin >> a;int i = 0;for (i = 0; i < n; i++){if (a == s[i]){cout << i << endl;break;}}if (i == n)cout << "No" << endl;}return 0;
}

特殊值结束测试数据

字符统计
#include <bits/stdc++.h>
using namespace std;int l, d, o;
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);int ch = 0;while ((ch = getchar()) != '?'){if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))l++;else if (ch >= '0' && ch <= '9')d++;elseo++;}cout << "Letters=" << l << endl;cout << "Digits=" << d << endl;cout << "Others=" << o << endl;return 0;
}
#include <bits/stdc++.h>
using namespace std;int l, d, o;
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);int ch = 0;while ((ch = getchar()) != '?'){if (islower(ch) || isupper(ch))l++;else if (isdigit(ch))d++;elseo++;}cout << "Letters=" << l << endl;cout << "Digits=" << d << endl;cout << "Others=" << o << endl;return 0;
}
#include <bits/stdc++.h>
using namespace std;int l, d, o;
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);int ch = 0;while ((ch = getchar()) != '?'){if (isalpha(ch))l++;else if (isdigit(ch))d++;elseo++;}cout << "Letters=" << l << endl;cout << "Digits=" << d << endl;cout << "Others=" << o << endl;return 0;
}
#include <bits/stdc++.h>
using namespace std;int l, d, o;
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);string s;getline(cin, s);s.pop_back();for (auto e : s){if (isalpha(e))l++;else if (isdigit(e))d++;elseo++;}cout << "Letters=" << l << endl;cout << "Digits=" << d << endl;cout << "Others=" << o << endl;return 0;
}
多组数据a+b 3
#include <bits/stdc++.h>
using namespace std;int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);int a, b;while(cin >> a >> b, a || b){cout << a + b << endl;}return 0;
}

逗号表达式:逗号隔开的一串表达式
特点:

  1. 从左向右依次计算
  2. 整个表达式的结果,是最后一个表达式结果
http://www.dtcms.com/a/446657.html

相关文章:

  • 10.5作业
  • C++进阶(8)——异常
  • Mybatis 主键配置错误做成查询数据丢失
  • wap自助建站排板网站维护 网站后台建设知识
  • Ubuntu中安装Nuclei教程
  • 关于旅游电子商务网站建设论文浙江联科网站建设
  • 什么网站可以兼职做设计国际新闻最新消息今天 新闻
  • 珠海专业网站建设费用河北建设局网站
  • 提高开发技能的Python设计模式
  • 网站方案模板购买网站空间ftp设计
  • python网站开发优缺网页微信版官网登录下载
  • dedecms 购物网站建设信息网的网站或平台登陆
  • 【C++实战(71)】解锁C++音视频开发:FFmpeg从入门到实战
  • 运营好网站wordpress 在线商店
  • C++初阶(12)vector
  • 库尔勒网站建设哪家好沈阳seo按天计费
  • DockerCE与cri-docker核心区别解析
  • 视频网站怎么做网站引流南阳企业网站
  • 深入理解 JavaScript 高阶函数:从 createScream 看函数式编程的优雅之道
  • 用户权限控制功能实现说明
  • 常见工厂后处理器作用
  • 公司免费网站制作云匠网接单
  • 网站建设与管理学习收获微信公众号免费模板网站
  • 企业可以做哪些网站做网站前端用什么语言
  • 阿里云服务器上传网站内容北京电力建设公司官网
  • 如何找到网站是谁做的哪家公司网站建设口碑好
  • Bootstrap 简介
  • 锡林浩特网站建设微信开发wordpress托管教程
  • 网站由什么组成网站备案更名
  • CPU高负载场景调优实战