int函数

[YTU]_2641 9 填空题:静态成员---计算学生个数)

断了今生、忘了曾经 提交于 2020-03-08 08:29:10
题目描述 学生类声明已经给出,在主程序中根据输入信息输出实际建立的学生对象个数,以及所有学生对象的成绩总和。 在下面的程序段基础上完成设计,只提交 begin 到 end 部分的代码 #include <iostream> #include <string> using namespace std; class student { private: stringname; // 学生姓名 intage; // 学生年龄 intscore; // 学生成绩 static intcount; // 记录学生对象个数 staticint sum; // 记录所有学生的总成绩 public: student(stringn,int a,int s); // 构造函数 staticint get_count(); // 静态成员函数,获取 count 的值 staticint get_sum(); // 静态成员函数,获取 sum 的值 }; // 将程序需要的成份写下来,只提交 begin 到 end 部分的代码 //******************** begin******************** int student::count=0; _____(1)_______; ________(2)___________ { name=n; age=a; score=s;

C++ map的基本操作和使用

戏子无情 提交于 2020-03-08 05:28:17
C++ map的基本操作和使用 来源:( http://blog.sina.com.cn/s/blog_61533c9b0100fa7w.html ) - C++ map的基本操作和使用_Live_新浪博客 Map是c++的一个标准容器,她提供了很好一对一的关系,在一些程序中建立一个map可以起到事半功倍的效果,总结了一些map基本简单实用的操作! 1. map最基本的构造函数; map<string , int >mapstring; map<int ,string >mapint; map<sring, char>mapstring; map< char ,string>mapchar; map<char ,int>mapchar; map<int ,char >mapint; 2. map添加数据; map<int ,string> maplive; 1.maplive.insert(pair<int,string>(102,"aclive")); 2.maplive.insert(map<int,string>::value_type(321,"hai")); 3, maplive[112]="April";//map中最简单最常用的插入添加! 3,map中元素的查找: find()函数返回一个迭代器指向键值为key的元素,如果没找到就返回指向map尾部的迭代器。 map

欧几里德算法(辗转相除法) 求最大公约数

元气小坏坏 提交于 2020-03-08 05:22:35
今天上课老师问"辗转相除法"又叫什么算法..居然没人知道..更居然的是..老师也忘了... 以前我貌似在VC的Samples里看到过这个算法, 似乎是叫欧几里德... 但也忘了是怎么辗转相除的.. 特此"百度知道"之: Euclid 欧几里德算法又称辗转相除法,用于计算两个整数a,b的最大公约数。其计算原理依赖于下面的定理: 定理:gcd(a,b) = gcd(b,a mod b) 证明:a可以表示成a = kb + r,则r = a mod b 假设d是a,b的一个公约数,则有 d|a, d|b,而r = a - kb,因此d|r 因此d是(b,a mod b)的公约数 假设d 是(b,a mod b)的公约数,则 d | b , d |r ,但是a = kb +r 因此d也是(a,b)的公约数 因此(a,b)和(b,a mod b)的公约数是一样的,其最大公约数也必然相等,得证。 欧几里德算法就是根据这个原理来做的,其算法用C++语言描述为: void swap(int & a, int & b) { int c = a; a = b; b = c; } int gcd(int a,int b) { if(0 == a ) { return b; } if( 0 == b) { return a; } if(a > b) { swap(a,b); } int c; for(c

1. LINQ入门学习记录—Lambda Expressions

落爺英雄遲暮 提交于 2020-03-08 02:35:05
1. 前言 2. Lambda表达式概念 3. Lambda表达式树的概念和示例 4. Lambda表达式的简单应用 5. 总结 前言 在LINQ刚发布的时候,一直也没有时间去研究下LINQ,特别是在当时各种LINQ to ***纷纷出现,看得眼花缭乱。 在LINQ中增加的lambda表达式一直觉得挺神秘的,看到各位高手把lambda表达式运用得如火纯清,很是羡慕. 最近抽 空学习了解了下LINQ, 对学习的过程进行记录。文章基础,高手请飘过 :-) 计划学习的主要内容是lambda表达式,LINQ to Objects, LINQ to XML. 三个部分。 学习之前,推荐一款帮助学习LINQ的优秀工具LINQPad,下载地址: LINQPad下载 。 【另注:学习过程未免出现差错,欢迎指正】 Lambda表达式的概念 什么是lambda表达式?Lambda 表达式是一种匿名函数,它可以包含表达式和语句,并且可用于创建委托或 表达式目录树类型。我们使用lambda表达式可以帮助我们编写精简和紧凑的代码,许多操作中允许自定义排序和过 滤的函数,在.NET2.0的时候通常使用委托函数来实现,在.NET3.5可以使用lambda表达式。 现在举例说明lambda表达式: Func<int,int> addOne= item=> item+1 ,其中操作符 “ => ”读作“Goes

HDU 1043 Eight

吃可爱长大的小学妹 提交于 2020-03-07 19:33:42
题目链接 康托展开与逆使用 题目思路演化过程 题目代码演化过程 感谢[kuangbin]的专题,太棒了,学到了许多 Problem Description The 15-puzzle has been around for over 100 years; even if you don’t know it by that name, you’ve seen it. It is constructed with 15 sliding tiles, each with a number from 1 to 15 on it, and all packed into a 4 by 4 frame with one tile missing. Let’s call the missing tile ‘x’; the object of the puzzle is to arrange the tiles so that they are ordered as: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 x where the only legal operation is to exchange ‘x’ with one of the tiles with which it shares an edge. As an example, the

团体程序设计天梯赛 L1-058 6翻了

烂漫一生 提交于 2020-03-07 19:29:02
L1-058 6翻了 题目链接-L1-058 6翻了 解题思路 思路1 for遍历字符串,记录查询由‘6’开头,查到后进行cnt++,判断有几个‘6’,如果9个‘6’以上的就直接输出‘27’,大于3个‘6’输出‘9’,否则输出cnt个‘6’,若不是由‘6’开头就直接输出s[i]即可 三目运算符可真香,小声bb 归纳一下 a ? b : c; 如果a为真,则执行b,否则执行c 函数 string(n,'c') 的功能是:返回由n个字符c组成的字符串 附上代码 # include <bits/stdc++.h> # define int long long # define lowbit(x) (x &(-x)) using namespace std ; const int INF = 0x3f3f3f3f ; const double PI = acos ( - 1.0 ) ; const double eps = 1e-10 ; const int M = 1e9 + 7 ; const int N = 1e5 + 5 ; typedef long long ll ; typedef pair < int , int > PII ; string s ; signed main ( ) { ios :: sync_with_stdio ( false ) ; cin . tie

C++加载运算符代码学习

五迷三道 提交于 2020-03-07 19:16:52
4.5 运算符重载 运算符重载概念:对已有的运算符重新进行定义,赋予其另一种功能,以适应不同的数据类型 4.5.1 加号运算符重载 作用:实现两个自定义数据类型相加的运算 class Person { public: Person() {}; Person(int a, int b) { this->m_A = a; this->m_B = b; } //成员函数实现 + 号运算符重载 Person operator+(const Person& p) { Person temp; temp.m_A = this->m_A + p.m_A; temp.m_B = this->m_B + p.m_B; return temp; } public: int m_A; int m_B; }; //全局函数实现 + 号运算符重载 //Person operator+(const Person& p1, const Person& p2) { // Person temp(0, 0); // temp.m_A = p1.m_A + p2.m_A; // temp.m_B = p1.m_B + p2.m_B; // return temp; //} //运算符重载 可以发生函数重载 Person operator+(const Person& p2, int val) { Person

【排序】--C语言实现堆排序

独自空忆成欢 提交于 2020-03-07 13:50:54
堆排序 堆排序使用【大顶堆】或者【小顶堆】实现。分为两步:构建堆和调整堆,主要时间都花在了构建堆上。堆排序效率比较高,适用于数据量比较大的场景。 代码 # include <stdio.h> /* 函数描述:构建大顶堆 函数参数:数组 根节点的下标 最后一个结点的下标 */ void AdjustMaxHeap ( int * a , int root , int last ) { int i , child ; int tmp = a [ root ] ; for ( ; 2 * root + 1 <= last ; root = child ) //循环到结点没有孩子结点为止 { child = 2 * root + 1 ; if ( child + 1 <= last && a [ child ] < a [ child + 1 ] ) //先找出两个孩子结点中较大的一个 { child ++ ; } if ( a [ child ] > a [ root ] ) //如果孩子结点比较大,则和根节点交换 { a [ root ] = a [ child ] ; a [ child ] = tmp ; } else { break ; } } } void swap ( int * x , int * y ) { int t = * x ; * x = * y ; * y =

录入学生信息,把学生信息存入磁盘文件中,创建一个简易的学生成绩管理系统。

给你一囗甜甜゛ 提交于 2020-03-07 10:35:18
创建学生成绩管理系统。 要求: 1、使用格式输入输出函数 2、学生信息包括:姓名、学号、3门课成绩(语数英) 3、学生信息存入cj.txt文件 4、能使用cat命令显示cj.txt文件内容。 一、源码 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 5 #define N 2 6 struct student 7 { 8 char name[10]; 9 int num; 10 int cscore; 11 int mscore; 12 int escore; 13 int sum; 14 }stu[N]; 15 void sum() //对语数外三门成绩求和 16 { 17 int i; 18 for(i=0;i<N;i++) 19 { 20 stu[i].sum=stu[i].cscore+stu[i].mscore+stu[i].escore; 21 printf(“num total score\n”); 22 printf("%d %d\n",stu[i].num,stu[i].sum); 23 } 24 return; 25 } 26 void seek() //输入学号进行查询 27 { 28 int i,item; 29 int flag=0; 30 printf(“please

dfs-1 全排列

孤街醉人 提交于 2020-03-07 09:32:57
一个超简单的全排列问题 最近开始学习了一点dfs,做了一点水题..... 水题虽然是水题,但不做水题怎么做更难的题呢 说的还挺有道理 然后呢,就写一哈我的一点心得体会 #include<bits/stdc++.h> using namespace std; int a[10],b[10]={0},n; void dfs(int step){ int i; if(step==n+1){ for(i=1;i<=n;i++){ printf("%d ",a[i]); } printf("\n"); return; } for(i=1;i<=n;i++){ if(b[i]==0){ b[i]=1; a[step]=i; dfs(step+1); b[i]=0; } } return; } int main(){ scanf("%d",&n); dfs(1); return 0; } 代码我也已经弄出来了,对大佬们来说弱智的一批,但对于我这种蒟蒻来说还是有一丢丢难度的, 怎么说呢,算法的思想我其实是能理解的,但在具体的实现过程中我搞不懂为什么第一次排列出1 2 3,之后第二次会出现1 3 2,之后等等一些排列不同的数,然后我就debug了一下,终于发现了问题所在,这个排列的数字之所以每次都不一样是由这个for循环中的i来控制的,dfs函数从上一级跳出来之后,可能有的for循环还没有结束