摘要: 一、const1、const必须在定义时初始化const int bufSize=512;2、const对象默认为文件的局部变量const double *cptr;//const指定了cptr指针指定的对象二、const引用const int ival=1024;const int &refVal=ival; //okint &ref=ival; //error------------------------------------------------------------------------------------------------------类成员函数中c 阅读全文
posted @ 2012-10-26 14:48 Afraid 阅读(131) 评论(0) 推荐(0)
摘要: 有n盏灯,编号为1~n,第1个人把所有灯打开,第2个人按下所有编号为2 的倍数的开关(这些灯将被关掉),第3 个人按下所有编号为3的倍数的开关(其中关掉的灯将被打开,开着的灯将被关闭),依此类推。一共有k个人,问最后有哪些灯开着?输入:n和k,输出开着的灯编号。k≤n≤1000#include<iostream>#define MAX 1000using namespace std;int main(){ int i,j,n,k,m; int flag[MAX]; cin>>n>>k; for(i=1;i<=n;i++) flag[i]=0... 阅读全文
posted @ 2012-10-07 10:50 Afraid 阅读(108) 评论(0) 推荐(0)
摘要: #include<iostream>#include<stdio.h>using namespace std;int main(){ int i,j,s,n; char ch; cin>>n; while(n--) { scanf("%x%c%x",&i,&ch,&j); if(ch=='+') s=i+j; else s=i-j; if(s>=0) printf("%o\n",s); else pr... 阅读全文
posted @ 2012-09-29 11:06 Afraid 阅读(168) 评论(0) 推荐(0)
摘要: #include<iostream>#define MAX 1000000using namespace std;int compute(unsigned int n){ int count=0,max=MAX; while(n/max==0) { max/=10; count++; } return 7-count;}int main(){ int i,m,num; unsigned int n,div; cin>>m; while(m--) { cin>>n; div=1; ... 阅读全文
posted @ 2012-09-20 22:28 Afraid 阅读(145) 评论(0) 推荐(0)
摘要: #include<iostream>using namespace std;int porc(int n,int m){ int a[3],b[3],flag[3]={0},count=0; a[2]=n%10; a[1]=(n/10)%10; a[0]=n/100; b[2]=m%10; b[1]=(m/10)%10; b[0]=m/100; if(a[2]+b[2]>=10) { count++; flag[2]++; } if(a[1]+b[1]+flag[2]>=10) { ... 阅读全文
posted @ 2012-09-20 15:37 Afraid 阅读(94) 评论(0) 推荐(0)
摘要: #include<iostream>#include<string>#include<math.h>#define MAX_NUM 100using namespace std;bool app(int n){ int i; if(n>=2) { for(i=2;i<=sqrt(double(n));i++) { if(n%i==0) return 0; } return 1; } else return 0;}int main(){ s... 阅读全文
posted @ 2012-09-19 23:30 Afraid 阅读(162) 评论(0) 推荐(0)
摘要: int、long、long long取值范围unsigned int 0~4294967295 int 2147483648~2147483647 unsigned long 0~4294967295long 2147483648~2147483647long long的最大值:9223372036854775807long long的最小值:-9223372036854775808unsigned long long的最大值:1844674407370955161__int64的最大值:9223372036854775807__int64的最小值:-9223372036854775808un 阅读全文
posted @ 2012-09-17 22:54 Afraid 阅读(191) 评论(0) 推荐(0)
摘要: #include<iostream>#include<math.h>using namespace std;int main(){ double a,b,c; int n; cin>>n; while(n--) { cin>>a>>b>>c; if(fabs(a+b-c)<0.00001) cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0;}注意:判断实数之间是否相等,不等用 阅读全文
posted @ 2012-09-17 22:28 Afraid 阅读(105) 评论(0) 推荐(0)
摘要: #include<iostream>using namespace std;int multiple(int a,int b){ int product=1; int i=2; while(i<=a&&i<=b) if(a%i==0&&b%i==0) { product*=i; a=a/i; b=b/i; i=2; } else i++; return pro... 阅读全文
posted @ 2012-09-17 10:58 Afraid 阅读(131) 评论(0) 推荐(0)
摘要: #include<iostream>#define MAX 100using namespace std;int main(){ int n,i=0,j=0,value=1; int a[MAX][MAX]={0}; cin>>n; j=n-1; while(value<=n*n) { while(i<n&&a[i][j]==0) { a[i][j]=value; i++; value++; } i--;j--; while... 阅读全文
posted @ 2012-09-12 01:22 Afraid 阅读(113) 评论(0) 推荐(0)