ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

无聊题解第1期

2022-08-08 08:00:08  阅读:125  来源: 互联网

标签:std cout 无聊 题解 eg C++ int include


今天,我要开始整一下无聊题解,小白们,看过来!

先说第一道题:

时间:1000ms
运行时的内存:262144kb

输入格式:
一行,有两个空格隔开的整数

样例输入:
1 2
样例输出:
3

这道题就是一道新手必刷题,那么先让我们来看一下A掉的代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    cout << a + b;
    return 0;
}

咱们从第一行开始解释:
1、

#include<bits/stdc++.h>

这句话在C/C++中具有重要地位,一旦不加,那么就会死翘翘。
为啥
首先来解释一下include这个词:
include在英文里面有包含,包括的意思,所以功能显而易见了吧。
就是把后面呢个带h的东西包括进去吗。
对头,但这个也有两种写法。

#include<bits/stdc++.h>
#include "bits/stdc++.h"

除了#include这种以外,还有不同种类的:
比如:

#include
#define
#if
#endif
#else
#elif
#undef
#line
#pragma

后面那个带h的文件其实叫做头文件,像我刚刚说的那个bits/stdc++.h,那么他的具体文件在哪里呢?
首先呢,得导到一个名为bits的文件夹,里面就会有stdc++.h的文件,里面的代码是这样的:

// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2016 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cuchar>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

这个库几乎把所有C++的库都包含进来了,但是也不是绝对的。
为哈呢?
因为在一些正规比赛当中,没人给你搞有这个头文件的编译包去,所以,这个是几个常用头,快点记下来吧!

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<cstdio>
#include<cstring>

好像也只有这几个,也拿不准,太长时间没敲了
2、

using namespace std;

所谓只要不在C++里面用C的方式写,命名空间没有就像一个人没有命根。
为什么ta如此重要?
大家都见过有些人写C++是这么写的:

#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b;
	cin >> a >> b;
	cout << a + b;
	return 0;
}

还有人是这么写的:

#include<bits/stdc++.h>
int main(){
	int a, b;
	std::cin >> a >> b;
	std::cout << a + b;
	return 0;
}

先谈一下命名空间到底是个啥?
这个东西就得与前面的头文件一起使用。
比如说:
头文件就好比是工具箱
命名空间恰好是工具
现在你要修你家的墙
没有工具哪行
这就是命名空间的道理

当然,这玩意也能这样使:

#include<bits/stdc++.h>
namespace bl{
	int a, b;
}
int main(){
	std::cin >> bl::a >> bl::b;
	std::cout << bl::a + bl::b;
	return 0;
}//只要不嫌麻烦,咋样造都行,毕竟还是要让程序成功运行就行

3、

int main(){}

这个东西不加,整个程序崩塌。
先来说一下ta的学名哈,就是一个mian函数,没错,是个函数。
首先说到函数就不得不提一嘴了。
函数这玩意吧,很神奇,还牵扯到变量的知识。
先说变量:
我们常见的变量有这几个:

int //eg 123
float //eg 3.1414
double //eg 3.14141414141441414414144141441
long long //eg 11111111111111111111111111111111111111111111111
unsigned int
unsigned float
unsigned double
unsigned long long
const int
const float
const double
const long long

char //eg a
string //eg abcdefg (C++ Only)
char[12] //eg qwertyuiopas

先说一说上面的变量,看到unsigned没,那种叫做无符号数。
那么,什么叫做有符号数,什么叫做无符号数呢?
大家都知道电脑是用二进制处理信息的,然而正常的八位二进制数分布:

10进制:+100
2进制:
01100100
拆分
0                        1100100
判断是正数还是负数         二进制转换,下期讲
0是正,1是负

有符号数是这样分布的,那么无符号的呢?

比如:201
在无符号情况下:
11001001
并没有区分符号的一位,这就是无符号数

说说const
const + 变量类型 + 变量名 + = + 想要赋的值
为什么必须这么写?
因为这玩意定义后就不能改动了。
string的事情下下期再说
函数下下下期细讲
cin和cout
cin相当于c的scanf
cout是printf
一个输入,一个输出
这个题解就完事了

债见!

标签:std,cout,无聊,题解,eg,C++,int,include
来源: https://www.cnblogs.com/areoflotpilotinappleinc/p/16560471.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有