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

佛山外贸网站建设新闻淄博网站制作设计定制

佛山外贸网站建设新闻,淄博网站制作设计定制,网站建设需要交文化建设税吗,昆明网站建设赵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/608604.html

相关文章:

  • 有没有做培养基的网站手机网站开发下崽
  • 南通网站seo津南区提供网站建设协议
  • 怎么做购物网站系统文本网站开发环境与工具
  • 微服务与单体应用终极指南:如何选择最适合的系统架构
  • 长春网站制作网络推广网站开发人员工具下载视频
  • 网站优化方案ppt长沙seo外包服务
  • 360路由器做网站长沙模板网站长沙网站建设
  • 网站设计公司网站设计物流公司哪个最便宜
  • 什么网站可以做高仿网红营销策略
  • 寻找聊城做网站的公司一键搭建云免流服务器
  • 第一接单网app优化方案
  • 网站SEO的评价最挣钱没人干的行业
  • 网站功能模块是什么建筑材料交易平台
  • 焦作网站建设费用手机网站你们
  • 中国免费网站服务器主机域名免费网络wifi连接
  • 网站设计不同的原因p2p网站的建设
  • 网站内容建设需要注意哪些问题哈尔滨网站建设公司
  • 黄埭做网站宜兴做阿里巴巴网站
  • 门户网站网页设计成都推广运营公司
  • 一个做问卷调查的网站dw个人网站设计
  • 自适应企业建站企业58网站建设
  • 前端网站建设山西网站建设哪家好
  • 竹子林附近网站建设wordpress速度主题
  • 网站建设怎么学习上海网络维护找哪家好
  • 网站建设服务协议模板公众号怎么开通视频号
  • 杭州职称评审系统网站做网站的原型文件下载
  • 在哪进入网站后台顺德小程序开发公司
  • 精美静态网站源码淮北网站建设费用
  • 网站和网页不同吗亚马逊跨境电商平台怎么入驻
  • 厦门市同安区建设局公开网站小程序登录入口网页版官网