(据我所知)C++ 不接受头文件上的“.h”扩展名(因为它通常不存在于其他包含语句中)所以包含如何<bits/stdc++.h>在 C++ 中工作以及为什么它有“.h”延期?
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int x;
int y;
cin >> x >> y;
if (x % 5 == 0 && x <= y) {
cout << y - x - 0.50 << "wow"
<< "\n";
} else {
cout << y << "\n";
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输入:
3
30 120.00
42 120.00
300 120.00
Run Code Online (Sandbox Code Playgroud)
输出:(当y为int时)
89.5wow
119.5wow
119.5wow
Run Code Online (Sandbox Code Playgroud)
在这里,即使第二和第三种情况应该给出 false 并运行else ,它也会运行if本身,而且不仅 …
我有一个代码。代码打印1236(g++ 7.5.0)
输出取决于编译器吗?(例如输出可以是3216)
#include <bits/stdc++.h>
using namespace std;
int foo(int& x) {
std::cout << ++x;
return x;
}
int main() {
int i = 0;
cout << foo(i) + foo(i) + foo(i) << endl; // 1236
}
Run Code Online (Sandbox Code Playgroud) 我已经将c ++转换为c类型字符串并使用strlen但它无法正常工作.
#include<bits/stdc++.h>
using namespace std;
int main(){
string s("Hello");
s.c_str();
cout<<strlen(s);
}
Run Code Online (Sandbox Code Playgroud) 我只是a使用容器类创建了一个数组。但是,VScode的IntelliSense显示错误。这是选择排序的实现。
该c_cpp_properties.json文件的内容如下
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.16299.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
Run Code Online (Sandbox Code Playgroud)
该代码将编译并成功运行。如何解决错误的IntelliSense错误?
Why the following code gives an error?
// This a CPP Program
#include <bits/stdc++.h>
using namespace std;
// Driver code
main()
{
string s=NULL;
s.length();
}
Run Code Online (Sandbox Code Playgroud)
I know that a runtime error will occur because I am trying to get the length of the null string but I want to know why it is happening?
我是 C++ 新手
我的问题是
我知道 unordered_map 使用散列,而 map 使用红黑树。但我很困惑,为什么 unordered_map 需要散列,而 map 不需要。可能是什么原因?
#include <bits/stdc++.h>
using namespace std;
struct hash_pair {
template <class T1, class T2>
size_t operator()(const pair<T1, T2>& p) const
{
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
int main()
{
unordered_map<pair<int, int>, int, hash_pair> hmap1;
hmap1[{1,1}]=2;
if (hmap1.find({1,1})!=hmap1.end()) cout<<"Value found :"<<hmap1[{1,1}]<<endl;
if (hmap1.find({0,0})==hmap1.end()) cout<<"Value not found"<<endl;
map<pair<int, int>, int> hmap2;
hmap2[{2,2}]=4;
if (hmap2.find({2,2})!=hmap2.end()) cout<<"Value found :"<<hmap2[{2,2}]<<endl;
if (hmap2.find({0,0})==hmap2.end()) cout<<"Value not …Run Code Online (Sandbox Code Playgroud) #include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
string s,e;
cin>>n;
vector <pair<string,string>> m(n);
for(int i=0;i<n;i++)
{
cin >> s >> e;
if (e.find("gmail")!=string::npos)
m[i]=make_pair(s,e);
}
sort(m.begin(),m.end());
auto it=m.begin();
while(it!=m.end())
{
cout<<it->first<<"\n";
it++;
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
julia
julia
riya
samantha
tanya
Run Code Online (Sandbox Code Playgroud)
我的输出是正确的,但是在开始时多打印了一行,因此我的测试用例都没有通过Hackerrank。
所以我有这个带有函数的代码,它应该将二维数组中的所有数字打印到二次幂,但我的代码不断抛出分段错误,我不知道为什么
#include <bits/stdc++.h>
using namespace std;
void er(int arr[][100000000], int, int);
int main()
{
int n, m;
cin >> n >> m;
int arr[n][100000000];
er(arr, n, m);
return 0;
}
void er(int arr[][100000000], int n, int m)
{
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> arr[i][j];
arr[i][j] *= arr[i][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = …Run Code Online (Sandbox Code Playgroud)