
C/C++
文章平均质量分 66
guofengzai
爱玩,求真,上进
展开
-
约瑟夫问题C++实现
#includeusing namespace std;int main(){ int N,M; cout cin>>N>>M; int* a=new int[N]; for(int i=0;i a[i]=i+1; } int countN=0; int countM=0; for(int i=0;;i++){原创 2008-03-27 12:08:00 · 1032 阅读 · 0 评论 -
HashTable索引法之折叠法--摘《多核计算与程序设计》)
哈希表的索引法有几种常见的方法,如整数取余法,折叠法,平方法。这里就介绍一下折叠法吧 当关键词位数很多时,可以将关键词分割为位数相同的几部分,每部分转换成计算机可以处理的整数,然后将各部分转换后的整数相加,得到一个新的整数,这就是折叠法。折叠法得到的整数不能直接作为关键词的索引,还需要前面介绍过的整数取余法来得到关键词的索引。 比如说字符串这种数据类型,便可以用折叠法来进行计算,下面给出一原创 2009-12-06 00:32:00 · 1902 阅读 · 2 评论 -
读写锁算法的伪代码实现---摘《多核计算与程序设计》
读写锁的数据结构:typedef struct RWLOCK_st{ LOCK ReadLock; LOCK WriteLock; UINT uReadcount;}RWLOCK; //读操作保护的伪代码 RWLock_LockRead(){ 上锁锁住计数器变量的读写 计数器加 1 if(计数器的值为 1)原创 2009-11-27 23:51:00 · 2245 阅读 · 0 评论 -
Java的数值精度的输出控制(包含BigDecimal)
import java.io.*;import java.text.*;import java.math.*;//import java.util.*;public class gaojingdutest { public static void main(String[] args){ //double 型数据的小数点控制输出 double a=1113.原创 2009-03-29 22:51:00 · 5934 阅读 · 1 评论 -
C++数值精度的输出控制
#include#includeusing namespace std;int main(){ double a= 12.3456789; cout<<a<<endl;//输出为12.3457,因为C++默认输出6位 cout<<setprecision(5)<<a<<endl;//输出为12.234,总的输出位数为5 cout<<setiosflags(i原创 2009-03-29 00:23:00 · 4011 阅读 · 1 评论 -
STL中的nth_element()方法的使用
STL中的nth_element()方法的使用 通过调用nth_element(start, start+n, end) 方法可以使第n大元素处于第n位置(从0开始,其位置是下标为 n的元素),并且比这个元素小的元素都排在这个元素之前,比这个元素大的元素都排在这个元素之后,但不能保证他们是有序的,下面是这个方法的具体使用方法.#pragma warning(disable: 4786)原创 2008-06-22 00:09:00 · 34838 阅读 · 7 评论 -
原来排序可以这样用,唉,可怜当时组队时
原来排序可以这样用,唉,可怜当时组队时不知道,竟然用vector存数据再用它自带的方法的排序,苦了我们,唉! 以下是C++中的sort()方法: #include #include using namespace std; int main(){ int a[8]={1,20,91,53,4,264,78,2}原创 2008-06-12 00:55:00 · 795 阅读 · 0 评论 -
初试指针---原来指针可以这样用啊!
#includeusing namespace std;int main(){ int a[10]={1,2,3,4,5,6,7,8,9,10}; int *p=a; int *q=&(a[0]); int *temp=a+10; int sum1=0,sum2=0; //两个for循环的结果是一模一样的 for(;p原创 2008-06-06 13:06:00 · 817 阅读 · 3 评论 -
08百度之星初赛:成语纠错
/* 成语纠错* 作者:国风崽* 不知道对还是错,请大家赐教*/#include#includeusing namespace std;int main(){ int n,m; scanf("%d%d", &n, &m); char a[n][400]; char b[m+1][9]; for(int i=0;i scanf("原创 2008-06-01 20:22:00 · 979 阅读 · 2 评论 -
Common Subsequence(PKU 1458)
/*题目二:Common Subsequence(PKU 1458)*作者:国风崽 */#include#includeusing namespace std;int main(){ char x[2000]; char y[2000]; while(scanf("%s %s",x+1,y+1)!=EOF){//获取输入按顺序放在数组除第一个元素的位置 in原创 2008-06-01 19:01:00 · 783 阅读 · 0 评论 -
The 3n + 1 problem(PKU 1207)
/*题目三:The 3n + 1 problem(PKU 1207)*作者:国风崽 */#includeusing namespace std;int main(){ int x,y; while(scanf("%d %d",&x,&y)!=EOF){ //while(cin>>x>>y){ int x1=x,y1=y; int maxL原创 2008-06-01 19:02:00 · 2043 阅读 · 1 评论 -
08百度之星初赛:钉子与木板
/* 钉子与木板* 作者:国风崽* 不知道对还是错,请人赐教*/#include using namespace std;int main(){ int n; int m; int b[4]; cin>>n; cin>>m; int a[n+1]; for(int i=1;i cin>>a[原创 2008-06-01 20:20:00 · 709 阅读 · 0 评论 -
Number triangle(PKU1163)
/*题目一:Number triangle(PKU1163)*作者:国风崽 */#include using namespace std;int main(){ int rows; cin>>rows;//输入三角数组的行数 int a[100][100];//直接声明一个100*100的数组,保证能存放所有的可能三角数组 for(int i原创 2008-06-01 18:59:00 · 725 阅读 · 0 评论 -
I Think I Need a Houseboat(PKU1005)
/*题目四:I Think I Need a Houseboat(PKU1005) *作者:国风崽*/#includeusing namespace std;int main(){ float x,y;//坐标 int testcase,t=0; cin>>testcase; while(testcase){ cin>>x>>y; ++t原创 2008-06-01 19:03:00 · 1000 阅读 · 0 评论 -
匹配一个字符串和另一个字符串的子串的方法
//匹配一个字符串和另一个字符串的子串的方法 #include#includeusing namespace std;int main(){ string str1; string str2; int count=0; getline(cin,str1);//可输入多行 getline(cin,str2);//可输入多行 int str1lgth=str1.size()原创 2008-04-05 22:48:00 · 1041 阅读 · 0 评论 -
小数点后面输出格式区别
用printf控制小数点后面几位的时候,一般都会四舍五入,但是有时候不能四舍五入,所以只能自己控制这时需要注意以下两种方式的区别#include main(){ float a = 3.3; a = a * 10; int b = (int)a; printf("%d\n",b); a = 3.3; b = int(a * 10); printf("原创 2012-01-06 22:39:09 · 712 阅读 · 0 评论