PAT甲级C++版
文章平均质量分 51
oney_hu
这个作者很懒,什么都没留下…
展开
-
C语言:字符串、结构体中关于数组的几个问题
【字符串】:1、字符串的储存:是基于数组实现的,(character string)是以空字符(\0)结尾的char数组。2、定义(基本的):【字符串常量】{ 又称为字符串文字,是指位于一对双引号中的任何字符,所以int a =“s”表示a被赋值一个指向字符串的地址,故这个式子是错误的。字符串常量是静态存储,const char *s="hello,everyone!" ;const原创 2015-11-15 16:07:29 · 1606 阅读 · 0 评论 -
变量作用域与this指针
【对于C语言来说】 【Global variables(全局变量)】 are declared outside all functions and are accessible in its scope.(在所有函数外面声明并在其作用域内可以被所有函数访问) The scope starts from its declaration and continues to the e原创 2016-02-20 01:14:42 · 354 阅读 · 0 评论 -
对象作为函数参数
You can pass objects by value or by reference.(对象作为函数参数,可以按值传递也可以按引用传递)//主函数#include <iostream>#include "Circle2.h"using namespace std;void printCircle(Circle c){//接受对象c cout << "The area of the原创 2016-02-20 11:00:48 · 452 阅读 · 0 评论 -
C++ 入门
1.A variable pointer to a constant value 变量指针指向一个常量数据 Shortly:Pointer to Constant(常量指针/常指针) 特征:指针指向的内容不可以通过指针的间接引用(*p)来改变 const int* p1; const int x = 1; //x 是常量 p1 = &x;原创 2016-02-19 13:58:44 · 256 阅读 · 0 评论 -
知行合一
PAT(1)最小子列和 算法一:在线算法 想法:maxsum、thissum、begin、last、thisbegin都为零 第一个A[0]开始累加,比最大的大就交换maxsum以及begin、last。如果和为负,这时改变thisbegin,last始终就是当前i 对于边界条件,如果全是负数,则sum记为零。原创 2015-11-07 15:15:28 · 626 阅读 · 0 评论 -
1004. Counting Leaves (30)
A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child. InputEach input file contains one test case. Each case starts with a line conta原创 2016-02-18 10:12:12 · 239 阅读 · 0 评论 -
1003. Emergency (25)
As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the le原创 2016-02-18 10:16:31 · 229 阅读 · 0 评论 -
1106. Lowest Price in Supply Chain (25)
【程序来自tiny656】 A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)– everyone involved in moving a product from supplier to customer.Starting from one root supplier, eve转载 2016-03-10 20:26:07 · 362 阅读 · 0 评论 -
随便写写C++,看看Essential C++
1.所谓“类”,是用户自定义的数据类型,class机制让我们得以将数据类型加入到我们的程序中,并有能力识别他们。class的定义一般分为两步:一是在头文件中声明,另一文件是程序代码文件,包含了这些操作行为的实现内容。2.初始化可以使用赋值符号”=” : int num_tries = 0; 也可以使用”构造函数语法” : int num_tries(0); 因为如果对象不是内置类型或者对象需原创 2016-03-13 21:14:10 · 688 阅读 · 0 评论 -
Essential C++ 之面向过程
#include <iostream>using namespace std;bool fibon_elem(int , int &);int main(){ int pos; cout << "Please entr a position: "; cin >> pos; int elem; if (fibon_elem (pos,elem))原创 2017-02-26 15:57:17 · 738 阅读 · 0 评论 -
C++数据域封装
Data Field Encapsulation (数据域封装)class Circle { //数据域采用public的形式有两个问题public: //First,data may be tampered (数据会被类外的方法篡改) double radius; //Second,it makes the clas原创 2016-02-19 19:42:40 · 1139 阅读 · 0 评论 -
C++字符串类
Constructing a String (创建string对象)Create an empty string using string’s no-arg constructor (用无参构造函数创建一个空字串)string newString;//Create a string object from a string value or from an array of characters原创 2016-02-19 19:12:43 · 438 阅读 · 0 评论 -
1104. Sum of Number Segments (20)
Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence {0.1, 0.2, 0.3, 0.4}, we have 10 segments: (0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (原创 2016-03-05 20:44:37 · 308 阅读 · 0 评论 -
重定向操作(C语言)
为了避免测试程序的时候输入太麻烦,可以使用文件 最简单的方法是使用输入输出重定向,只需在main函数的入口处加入以下语句:freopen{"input.txt","r",stdin};freopen{"output.txt","w",stdout};将使scanf从文件input.txt读入,printf写入文件output.txt。原创 2016-02-05 20:03:21 · 899 阅读 · 0 评论 -
快速排序
编译器函数库自带的快速排序函数。qsort 的函数原型是void qsort(void*base,size_t num,size_t width,int(__cdecl*compare)(const void*,const void*));参数: 1 待排序数组首地址 2 数组中待排序元素数量 3 各元素的占用空间大小 4 指向函数的指针,用于确定排序的顺序其中cmp函数可以自己写int原创 2016-02-06 02:07:30 · 231 阅读 · 0 评论 -
不定期更新
【1】 int sum(int (*ar) [ ][20][32]); 一般的,在声明N维数组的指针的时候,除了最右边的方括号可以留空之外,其他都要写上大小。 【2】 指针一定要先初始化,才能赋值。 【3】 字符串的输入: scanf( )函数在遇到空白符的时候就停止了 gets( )函数不会在意是否空间够用,会将数据读到其他地址中去。 【4】 memcpy(a,b,sizeo原创 2015-11-15 17:31:06 · 446 阅读 · 0 评论 -
1002. A+B for Polynomials (25)
This time, you are supposed to find A+B where A and B are two polynomials.InputEach input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial原创 2016-02-18 09:50:56 · 221 阅读 · 0 评论 -
关于map
输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文 本中的另外一个单词。在判断是否满足条件时,字母不分大小写,但在输出时应保留输入中 的大小写,按字典序进行排列(所有大写字母在所有小写字母的前面)。 样例输入: ladder came tape soon leader acme RIDE lone Dreis peat ScAlE orb eye Rides de原创 2016-03-03 16:12:43 · 380 阅读 · 0 评论 -
1001. A+B Format (20)
Calculate a + b and output the sum in standard format – that is, the digits must be separated into groups of three by commas (unless there are less than four digits).InputEach input file contains one t原创 2016-02-17 17:23:45 · 290 阅读 · 0 评论 -
1005. Spell It Right (20)
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.Input Specification:Each input file contains one test case. Each cas原创 2016-03-04 18:52:11 · 263 阅读 · 0 评论 -
1006. Sign In and Sign Out (25)
At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in’s and out’s, you原创 2016-03-04 19:02:15 · 328 阅读 · 0 评论 -
创建函数并访问
class Circle{public: double radius; Circle() { //Constructors: radius = 1; //Initialize objects(构造函数:初始化对象) }原创 2016-02-19 14:38:18 · 225 阅读 · 0 评论 -
Essential C++ 之 编程基础
(1) 常识:page 1 - 25布尔值:字符:整数:浮点数:算数运算符:关联运算符:逻辑运算符:等号运算符:小于等于符:赋值运算符:累加运算符:条件运算符:复合运算符:条件分支:循环控制:抽象化程序库:字符串,向量vector示例:#include <iostream>#include <string>using namespace std;int main(原创 2017-02-25 22:43:36 · 499 阅读 · 1 评论