• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
 






wj903829182

 
 

Powered by 博客园
博客园 | 首页 | 新随笔 | 联系 | 订阅 订阅 | 管理

2012年10月26日

因子数问题
摘要: #include<iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>using namespace std;const int Max = ( 1 << 20 ) + 5;long long len[Max],hash[Max];int n;void pre( ){ for( int i = 1; i <= Max / 2; ++i ) { for( int j = i + i; j < Max; j += i 阅读全文
posted @ 2012-10-26 15:07 903829182 阅读(154) 评论(0) 推荐(0)
 
STL
摘要: 所谓序列式容器,其中的元素都可序,但未必有序,C++语言本身提供了一个序列式容器arry,STL再提供vector,list,deque,stack,queue,priority_queue等等序列式容器,其中stack和queue只是将deque改头换面,技术上被归类为一种配接器.一 vectorvector的数据安排以及操作方式与arry十分相似,唯一的差别在于arry是静态的,一旦配置了就不能改变,vector是动态空间.stl的erase和insert 的实现效率低得可怜,每erase一个元素,竟然要把后面所有的节点全部移动,O(n^2)的复杂度.vector有个resize函数,原型 阅读全文
posted @ 2012-10-26 15:03 903829182 阅读(184) 评论(0) 推荐(0)
 
数据结构上机3
摘要: #include<stdio.h>#define max 100///////////////////////typedef struct{ int queue[max]; int front; int rear; int cout;}SeqQueue;/////////////////////////int InSeqQueue(SeqQueue &s){s.cout=0;s.front=0;s.rear=0;}/////////////////////////////////int InQuee(SeqQueue &s,int x){if(s.cout>0 阅读全文
posted @ 2012-10-26 14:53 903829182 阅读(102) 评论(0) 推荐(0)
 
数据结构上机2
摘要: #include<stdio.h>/////////////////////////////////////typedef struct Node{int data; struct Node *next;}LNode,*LinkList;////////////////////////////////////////////int InList(LNode &L){ LinkList p; p=&L; p=new Node(); p->data=0; p->next=NULL; return 0;}//////////////////////////// 阅读全文
posted @ 2012-10-26 14:52 903829182 阅读(136) 评论(0) 推荐(0)
 
数据结构上机1
摘要: #include<stdio.h>#include<malloc.h>#include<stdlib.h>////////////////////////////////////////////////typedef struct{int *element;int length;int listsize;}SeqList;////////////////////////////////////////////////int InitSeqList(SeqList &S){ S.element=(int *)malloc(sizeof(int)*100 阅读全文
posted @ 2012-10-26 14:51 903829182 阅读(123) 评论(0) 推荐(0)
 
c++变量的使用
摘要: /*#include<iostream>#include<iomanip>#include<stdlib.h>using namespace std;int main() {system("color 3E");int a=10;int &b=a;a=a*a;cout<<a<<" "<<b<<endl;b=b/5;cout<<a<<" "<<b<<endl;return 0;}*/#include 阅读全文
posted @ 2012-10-26 14:37 903829182 阅读(175) 评论(0) 推荐(0)
 
猜数字游戏
摘要: /*#include<iostream>#include<stdlib.h>#include<string>using namespace std;int main(){string st[5];system("color 3E");int i;cout<<"输入五个字符串:\n"; cout<<"*******\1 \1 \1 \1 \1 \1 \1 \1*******\n";for(i=0;i<5;i++){cin>>st[i];}for(i=0;i&l 阅读全文
posted @ 2012-10-26 14:36 903829182 阅读(147) 评论(0) 推荐(0)
 
c++控制函数的使用
摘要: /*#include<iostream>#include<stdio.h>#include<stdlib.h>#include<windows.h>using namespace std;int main(){system("color 3E");cout<<"响三次:\n";Sleep(1000);cout<<'\a';Sleep(1000);cout<<'\a';Sleep(1000);cout<<'\a'; 阅读全文
posted @ 2012-10-26 14:35 903829182 阅读(158) 评论(0) 推荐(0)
 
周期串
摘要: #include<stdio.h>#include<string.h>int main(){char word[100];scanf("%s",word);int len=strlen(word);for(int i=1;i<=len;i++)if(len%i==0){int ok=1;for(int j=i;j<len;j++)if(word[j]!=word[j%i]){ok=0;break;}if(ok){printf("%d\n",i);break;}}return 0;} 阅读全文
posted @ 2012-10-26 14:34 903829182 阅读(158) 评论(0) 推荐(0)
 
大数相加问题
摘要: #include<iostream>#include<string>using namespace std;string add(string a, string c) { char ab[255]; memset(ab,'\0',sizeof(char)*255); for(unsigned int i_=0;i_< a.length();i_++) ab[i_]=a[a.length()-i_-1]; char cd[255]; memset(cd,'\0',sizeof(char)*255); for(unsigned int 阅读全文
posted @ 2012-10-26 14:33 903829182 阅读(184) 评论(0) 推荐(0)
 
高精度运算
摘要: #include<iostream>#include<string.h>using namespace std;const int max=1000;struct bign{int len,s[max];bign(){memset(s,0,sizeof(s));len=1;}bign operator = (const char * num){len=strlen(num);for(int i=0;i<len;i++)s[i]=num[len-1-i]-'0';return *this;} bign operator = (int num){cha 阅读全文
posted @ 2012-10-26 14:32 903829182 阅读(122) 评论(0) 推荐(0)
 
数列求和
摘要: #include<stdio.h>#include<stdlib.h>int main(){ system("color 3E");int i=1,j=1,n;long sum=0,s=0;printf("输入项数N\n");scanf("%d",&n);if(n<1){printf("the n must be no less than 1!\n");return 0;} for(;i<=n;i++){for(;j<=i;j++){s=s+i;}sum=sum+s 阅读全文
posted @ 2012-10-26 14:31 903829182 阅读(110) 评论(0) 推荐(0)
 
素数
摘要: #include<stdio.h>#include<math.h>int main(){long n,m,a[100000];int i,j,k,t=1;scanf("%ld",&n);a[0]=2;m=3; while(m<n){k=0;while(a[k]*a[k]<=m)if(m%a[k]==0){m=m+2; k=1;}elsek++;a[t++]=m;m=m+2;}for(i=0;i<t-1;i++)printf("%ld\n",a[i]);return 0;} 阅读全文
posted @ 2012-10-26 14:30 903829182 阅读(101) 评论(0) 推荐(0)
 
余弦问题
摘要: #include<iostream>#include<math.h>#include<stdlib.h>using namespace std;int main(){ system("color 3E"); double y;int x,m;for(y=1;y>=-1;y-=0.1){m=acos(y)*10;cout<<m;for(x=1;x<m;x++)cout<<" ";cout<<"*";for(;x<62-m;x++)cout<& 阅读全文
posted @ 2012-10-26 14:29 903829182 阅读(130) 评论(0) 推荐(0)
 
指针小结
摘要: /*#include<stdio.h>void main(){ printf(" ******用指针访问变量*******\n");int a=521,*p=&a;printf(" %d %d\n",&a,p);printf(" %d %d\n",*&a,*p);printf(" %d %d\n",(&a)[0],p[0]);}*///&&&&&&&&&&&&&& 阅读全文
posted @ 2012-10-26 14:28 903829182 阅读(101) 评论(0) 推荐(0)
 
字符倒叙问题
摘要: #include<stdio.h>#include<string.h>int main(){char str[30],ch;int i=0,j; gets(str);for(i,j=strlen(str);i<j;i++,j--){ch=str[i];str[i]=str[j-1];str[j-1]=ch;}puts(str);return 0;} 阅读全文
posted @ 2012-10-26 14:28 903829182 阅读(123) 评论(0) 推荐(0)
 
最大公约数和最小公倍数
摘要: #include<stdio.h>#include<stdlib.h>void main(){long n,m,r,t,c;system("color 3E");printf("输入两个数\n");scanf("%ld%ld",&n,&m);if(n<1||m<1){printf("输入错误\n");exit(0);}if(n>m){t=n;n=m;m=t;}c=m*n;r=m%n;while(r!=0){m=n;n=r;r=m%n;}printf(&quo 阅读全文
posted @ 2012-10-26 14:27 903829182 阅读(107) 评论(0) 推荐(0)
 
求字符的个数
摘要: #include<stdio.h>#include<stdlib.h>void main(){char ch;int a=0,b=0,c=0,d=0;system("color 3E");printf("输入字符\n");ch=getchar();while(ch!='\n'){if(ch>='A'&&ch<='z')a++;else if(ch==' ')b++;else if(ch>='0'&&ch 阅读全文
posted @ 2012-10-26 14:25 903829182 阅读(126) 评论(0) 推荐(0)
 
求π的近视值
摘要: #include<stdio.h>#include<stdlib.h>#include<math.h>void main(){double sn=0,t,n=1.0;int s=1;system("color 3E");t=1.0/n;while(fabs(t)>1e-6){sn=sn+t;n=n+2;s=-s;t=s/n;}printf("1-1/3+1/5-1/7....=%.6lf\n",sn*4);} 阅读全文
posted @ 2012-10-26 14:24 903829182 阅读(164) 评论(0) 推荐(0)
 
n阶的和
摘要: #include<stdio.h>#include<stdlib.h>void main(){int n,i;long sn=0,t=1;system("color 3E");printf("***输入n***\n");scanf("%d",&n);for(i=1;i<=n;i++){t=t*i;sn=sn+t;}printf("1!+2!+3!...+N1=%ld\n",sn);} 阅读全文
posted @ 2012-10-26 14:23 903829182 阅读(148) 评论(0) 推荐(0)
 
2+22+222+2222问题的通解
摘要: #include<stdio.h>#include<stdlib.h>void main(){int a,n,i;long sn=0,t;system("color 3E");printf("输入A和N\n");scanf("%d%d",&a,&n);t=a;for(i=1;i<=n;i++){sn=sn+t;t=t*10+a;}printf("sn为%ld\n",sn);} 阅读全文
posted @ 2012-10-26 14:22 903829182 阅读(341) 评论(0) 推荐(0)
 
链表的处理
摘要: #include<stdio.h>#include<stdlib.h>#include<conio.h>struct node *head;struct node{int date;struct node *next;};//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 阅读全文
posted @ 2012-10-26 14:17 903829182 阅读(129) 评论(0) 推荐(0)
 
链表的处理问题
摘要: #include<stdio.h>#include<stdlib.h>#include<conio.h>struct node *head;struct node{int date;struct node *next;};//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& 阅读全文
posted @ 2012-10-26 14:17 903829182 阅读(162) 评论(0) 推荐(0)
 
猴子吃桃问题
摘要: #include<stdio.h>#include<stdlib.h>int main(){int s=1,i;system("color 3E");for(i=10;i>1;i--){s=(s+1)*2;}printf("共有桃%d个\n",s);return 0;} 阅读全文
posted @ 2012-10-26 14:16 903829182 阅读(116) 评论(0) 推荐(0)
 
分数序列的前20项和
摘要: #include<stdio.h>#include<stdlib.h>int main(){int f1=1,f2=2,i,n=20,t;double sum=0;system("color 3E");for(i=1;i<=n;i++){sum=sum+f2*1.0/f1;t=f1;f1=f2;f2=t+f2;}printf("%lf\n",sum);return 0;} 阅读全文
posted @ 2012-10-26 14:15 903829182 阅读(201) 评论(0) 推荐(0)
 
迭代法求平方根
摘要: #include<stdio.h>#include<stdlib.h>#include<math.h>int main(){double x1=0,x2=1.0;int a;system("color 3E");printf(" 输入你要求的数\n");scanf("%d",&a);while(fabs(x2-x1)>1e-5){x1=x2;x2=0.5*(x2+a/x2);}printf("所求为%.4lf\n",x2);return 0;} 阅读全文
posted @ 2012-10-26 14:14 903829182 阅读(126) 评论(0) 推荐(0)
 
二次函数的根
摘要: #include<stdio.h>#include<math.h>int main(){int a,b,c,t;double p,q,d,x1,x2;scanf("%d%d%d",&a,&b,&c);t=b*b-4*a*c;if(t==0){x1=-b/2*a*1.0;x2=x1;printf("x1=%.3f x2=%.3f\n",x1,x2);}else if(t>0){d=sqrt(t);x1=(-b+d)/2*a;x2=(-b-d)/2*a;printf("x1=%.3f x2=%. 阅读全文
posted @ 2012-10-26 14:14 903829182 阅读(227) 评论(0) 推荐(0)
 
打印杨辉三角
摘要: #include<stdio.h>#define n 10void main(){int i,j,s[n][n]={0};s[0][0]=1;printf("%4d\n",s[0][0]);for(i=1;i<n;i++){s[i][0]=1;printf("%4d",s[i][0]);for(j=1;j<n;j++){s[i][j]=s[i-1][j-1]+s[i-1][j];printf(s[i][j]!=0?"%4d":" ",s[i][j]);}printf("\n&quo 阅读全文
posted @ 2012-10-26 14:13 903829182 阅读(81) 评论(0) 推荐(0)
 
乘法口诀表
摘要: #include<stdio.h>#include<stdlib.h>void main(){int i,j,x,y;system("color 3E");for(i=1;i<=9;i++){for(j=1;j<=i;j++){printf("%d*%d=%2d ",j,i,j*i);}printf("\n");}printf("\npress any key to quit........\n");getchar();} 阅读全文
posted @ 2012-10-26 14:12 903829182 阅读(127) 评论(0) 推荐(0)
 
100000000素数
摘要: #include<stdio.h>#include<stdlib.h>#define NMAX 10000000#define SQRN 10000int main(){ int n; static char a[NMAX]; unsigned long k,i;scanf("%d",&n); for(k=2;k<=SQRN;k++)if(!a[k])for(i=2*k;i<n;i+=k) a[i]=1; for(i=2;i<n;i++)if(!a[i]) {printf("%ld\n",i); }ret 阅读全文
posted @ 2012-10-26 14:10 903829182 阅读(150) 评论(0) 推荐(0)
 
1000以内的完数
摘要: #include<stdio.h>#include<stdlib.h>#include<math.h>int pdwshu(int n,int *k){int s=0,i;for(i=1;i<=n/2;i++){if(n%i==0){s=s+i;*k=*k+1;}}if(s==n){ printf("%d its factors are ",n);return 1;}elsereturn 0;}void pri(int n,int k){int i,j=0;for(i=1;i<=n/2;i++){if(n%i==0){j++; 阅读全文
posted @ 2012-10-26 14:09 903829182 阅读(188) 评论(0) 推荐(0)
 
1000以内的水仙花数
摘要: #include<stdio.h>#include<stdlib.h>void main(){int i,j,k,l;system("color 3E");for(i=101;1<1000;i++){j=i%10;k=i/10%10;l=i/100%10;if(i==j*j*j+k*k*k+l*l*l)printf("%d is shui xian hua shu\n",i);}} 阅读全文
posted @ 2012-10-26 14:08 903829182 阅读(244) 评论(0) 推荐(0)
 
三天打鱼2天嗮网问题
摘要: #include<iostream>#include<stdio.h>#include<stdlib.h>using namespace std;int main() // 三天打鱼两天晒网,周期为五天,假设1990年一月一日为{long sum=0;int year,month,day,i,j,n,t;int a[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};//system("color 3E");cou 阅读全文
posted @ 2012-10-26 13:58 903829182 阅读(130) 评论(0) 推荐(0)