C++知识
xiaohanstu
屌丝码农一枚!
展开
-
九度OJ 1002:grading
/**********************************题目:九度OJ1002:grading作者:xiaohanstu日期:2013-10-14结果:AC **********************************/#include#include#includeusing namespace std;float max(f原创 2013-10-14 17:34:30 · 699 阅读 · 0 评论 -
N皇后问题
#includeusing namespace std;int vis[3][30];//分别表示列,主对角线和副对角线是否被占用,若用(row,col)表示第row行第col列位置(row,col)均从0开始//则列所在位置为col,主对角线所在位置为n-row+col,副对角线所对应的位置为row+colint ans ,MAXN;void dfs(int row){ if (r原创 2014-12-11 10:33:37 · 709 阅读 · 0 评论 -
百分制成绩
#include #include #include "oj.h"using namespace std;/*功能: 给出一百分制成绩,要求输出成绩等级‘A’、‘B’、‘C’、‘D’、‘E’。 90分以上为A 80-89分为B 70-79分为C 60-69分为D 60分以下为E输入: 整数score输出: 无返回: 分级结果 分数不在100范围时返回-1*/原创 2014-12-11 15:25:30 · 965 阅读 · 0 评论 -
周期串问题
#include "OJ.h"#include using namespace std;/*功能:计算字符串的最小周期。原型: int GetMinPeriod(char *string);输入参数: char * string:字符串。返回值: int 字符串最小周期。思路:使用i表示字符串可能的周期,从周期为1开始逐渐增大1,当i满足是字符串的原创 2014-12-10 18:18:47 · 773 阅读 · 0 评论 -
查找同构数的数量
#include "OJ.h"#include using namespace std;bool isSameConstructNum(int m)//判断m是否是同构数{ int squareM = m*m; int initialM = m*m; int temp = 0; int partialNum =0; int interNum = 1;//存储对应位数需要成的倍原创 2014-12-11 16:09:15 · 1610 阅读 · 0 评论 -
字符串最后一个单词的长度
/*题目:字符串最后一个单词的长度*///思路:使用getline接收一串字符,使用string的length函数获取字符串长度,从字符串的最后访问并记录长度,直到遇到空白符空格或tab#include #include using namespace std;int getLastStringLen(string &s){int len = s.length(原创 2014-12-10 09:47:04 · 830 阅读 · 0 评论 -
奖金提成
#include #include#include "oj.h"using namespace std;/*功能: 企业发放的奖金根据利润提成。 利润低于或等于100000元的,奖金可提10%; 利润高于100000元,低于200000元(100000<I≤200000)时; 低于100000元的部分按10%提成; 高于100000元的部分,可提成 7.5%; 200000原创 2014-12-13 09:45:01 · 1104 阅读 · 0 评论 -
求M的N次方的最后三位
#include #include #include "oj.h"using namespace std;//思路:每次相乘,仅保留积的最后三位unsigned int GetLastThreeNumOfResult (unsigned int m, unsigned int n){ unsigned int result = m %1000; for (int i =1原创 2014-12-13 10:50:44 · 1981 阅读 · 0 评论 -
判断任意两台计算机的IP地址是否属于同一子网络
#include "OJ.h"#include#includeusing namespace std;/*功能: 判断两台计算机IP地址是同一子网络。原型: int IsSameSubNetwork(char * pcIp1, char * pcIp2, char * pcSubNetworkMask);输入参数: char * pcIP1: 计算机1的IP地址,格原创 2014-12-13 10:27:13 · 1613 阅读 · 0 评论 -
求某二进制数中1的个数
#include "OJ.h"#include using namespace std;/*Description 给定一个unsigned int型的正整数,求其二进制表示中“1”的个数,要求算法的执行效率尽可能地高。Prototype int GetCount(unsigned int num)Input Param nu原创 2014-12-13 11:14:34 · 560 阅读 · 0 评论 -
求车速
#include "OJ.h"#include#includeusing namespace std;/*功能: 根据里程计算车速原型: int CalcSpeedOfCar(int iCurrentMileage, int * piCarSpeed);输入参数: int pcCurrentMileage:当前里程数(为对称数)(pcCurrentMileage原创 2014-12-13 14:22:03 · 1451 阅读 · 0 评论 -
阿姆斯特朗数
#include "OJ.h"#includeusing namespace std;/*功能: 求n(n ≤ 65536)以内的所有阿姆斯特朗数原型: int CalcArmstrongNumber(int n);输入参数: int n: n ≤ 65536返回值: n以内的阿姆斯特朗数的数量。*/bool isArmstrongNumber(in原创 2014-12-11 15:01:08 · 844 阅读 · 0 评论 -
C++的四种cast操作符的区别--类型转换
C++的四种cast操作符的区别并非我的原创,来自互联网,且是两篇帖子的合集,个人觉得这样才比较完备----------------------------------------------------------------------Q:什么是C风格转换?什么是static_cast, dynamic_cast 以及 reinterpret_cast?区别是什么?为什转载 2014-05-23 18:36:36 · 426 阅读 · 0 评论 -
九度 OJ1001:A+B for Matrices
/*********************题目:九度 OJ1001:A+B for Matrices 作者:xiaohanstu日期:2013-10-14结果:AC**********************/#includeusing namespace std;int main(){int M,N;int matA[11][11];wh原创 2013-10-14 16:45:37 · 518 阅读 · 0 评论 -
九度OJ 1004
/*******************题目:九度OJ 1004作者:xiaohanstu日期:2013-10-16 *******************/#includeusing namespace std;int main(){int M,N;while(cin>>M){int *A=new int [M];for(int n=0原创 2013-10-16 22:54:00 · 626 阅读 · 0 评论 -
九度OJ 1003:A+B
/*******************题目:九度OJ 1003:A+B作者:xiaohanstu日期:2013-11-2语言: C++ 思路:先将A,B字符串中的逗号去掉,再用atoi函数将其转换成整型相加即可; 结果:AC *******************/#include#include#includeusing namespace st原创 2013-11-02 22:08:10 · 666 阅读 · 0 评论 -
九度OJ 1202:排序
/*******************题目:九度OJ 1202:排序 作者:xiaohanstu日期:2013-11-02 语言: C++ 结果:AC *******************/#include#includeusing namespace std;int main(){int n;while(cin>>n){int *原创 2013-11-02 22:48:19 · 635 阅读 · 0 评论 -
C++创建动态二维数组
//c++中数组的维数不能设置为变量,如果维度要设置为变量,则要使用动态二维数组。下面的程序展示了二维动态数组的定义、初始化、赋值、输出与销毁的全过程。#includeusing namespace std;int main(){//创建并销毁二维动态数组int m=2,n=2;int **p=new int *[m];for (int i=0;i{原创 2014-01-09 09:31:48 · 1035 阅读 · 0 评论 -
根据一组点拟合曲线(需要opencv库)
matlab中跟据点拟合方程灰常容易,直接使用polyfit函数就行了。C++貌似没有直接拟合曲线的函数,在下不才,就用C++结合opencv的库函数写了个拟合曲线的函数。#include #include #include using namespace std;//函数功能:根据vec中存储的点的坐标拟合曲线;//vec为为存储点坐标的容器,index为存储拟合原创 2014-03-07 14:35:19 · 10507 阅读 · 2 评论 -
编程导论中 堆排序 C++实现
#includeusing namespace std;void max_heapify(int *A,int i,int heap_size)//heap_size既为A的数组长度,也为堆的大小,i是数组中第i个节点,该函数的功能是将以i为根的子树按堆的性质排列;{int largest=i;int l=(iint r=(iif (lA[i])){la原创 2014-03-25 14:39:31 · 513 阅读 · 0 评论 -
关于课程学习
http://www.zhihu.com/question/22608820感觉写的不错。陈硕,Linux C++程序员,muduo 网络库作者高飞、HU Shi、zc5678 等人赞同既然你是在校学生,而且编程语言和数据结构的基础还不错,我认为应该在《操作系统》和《计算机体系结构》这两门课上下功夫,然后才去读编程方面的 APUE、UNP 等书。下面简单谈谈我对学习这两门课的看法和转载 2014-09-18 20:34:10 · 705 阅读 · 0 评论 -
类的成员函数是否可以做为回调函数?
许多程序员都发现,利用MFC或者其它的C++应用编写回调函数是非常麻烦的,其根本原因是回调函数是基于C编程的Windows SDK的技术,不是针对C++的,程序员可以将一个C函数直接作为回调函数,但是如果试图直接使用C++的成员函数作为回调函数将发生错误,甚至编译就不能通过。通过查询资料发现,其错误是普通的C++成员函数都隐含了一个传递函数作为参数,亦即“this”指针,C++通过传递一个指向自身转载 2014-09-10 11:50:11 · 496 阅读 · 0 评论 -
对象管理器
//ObjMgt.h#ifndef __OBJMGT_H__#define __OBJMGT_H__int AddObject (unsigned int key1, unsigned int key2, unsigned int key3);void DeleteObject (unsigned int key1, unsigned int key2, unsigned i原创 2014-12-15 20:50:53 · 946 阅读 · 0 评论 -
双链表基本操作
#include #include using namespace std;#define null 0#define MAXSIZE 50struct strlnode{ int data; struct strlnode *plast; struct strlnode *pnext;};void create(struct strlnode **p, int x)原创 2015-05-06 10:41:14 · 612 阅读 · 0 评论