博文

C++吧第2界编程大赛(网友算法)(2005-11-29 15:23:00)

摘要://第一题(222.173.180.*   ) #define leap(year) ((!(year%4) && year%100) || !(year%400))  int main() {   long year,month=1,day=1; //program safty??? printf("please input the date:format like YYYY-MM-DD\n"); scanf("%d-%d-%d",&year,&month,&day);  month>10?year++,month-=10:month+=2; //month okey... if(day==31&&month==9) day=30; //kill 31  if(day>28&&month==2) leap(year)?day=29:day=28; printf("%.4d-%.2d-%.2d\n",year,month,day); //out  return 0; } //第2题(Soningwl) #include<iostream.h>  #include<math.h>  int main()  {  cout<<"请输入一个年份:(1946-2246)";  int num;   cin>>num;  long double a;  a=pow(2,(num-1946)/10);  int i=1;  long double sum=0;  for(;sum<a*log(2);i++)sum+=log(i);&n......

阅读全文(4281) | 评论:0

C++吧第2界编程大赛(算法)(2005-11-29 15:19:00)

摘要:http://post.baidu.com/f?kz=66887754 //第一题#include <stdio.h> int m_day(int year,int month)/*此函数是给定年,月,计算此月有多少天.*/ { if ((year%4==0 &&year%100!=0) || (year%400==0)) switch(month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 4: case 6: case 9: case 11: return 30; case 2: return 29; } else  switch(month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 4: case 6: case 9: case 11: return 30; case 2: return 28; } } int main(){ int y,m,d; while(scanf("%d-%d-%d",&y,&m,&d)) {  m+=2;  if(m>12)  {   m-=12;   y+=1;  }  if(d>m_day(y,m))   d=m_day(y,m);  printf("%d-",y);  if(m<10)   printf("0");  printf("%d-",m);  if(d<10)   printf("0");  printf("%d\n",d); }}   //第2题#include <iostream.h>#in......

阅读全文(4427) | 评论:0

C++(66856786)(2005-11-23 16:57:00)

摘要:#include <fstream.h>#include <stdlib.h> struct stu{char num[10];int score[5];int total;}S[119]; int comp(const void* a,const void *b){ struct stu *s1=(struct stu *)a; struct stu *s2=(struct stu *)b; return (s1->toatl-s2->total);} int main(){ifstream fin("Data.txt");ofstream fout("Result.txt");int i,j;for(i=0;i<119;i++){ fin>>S[i].num; S[i].total=0; for(j=0;j<5;j++) {  fin>>S[i].score[j];  S[i].toatl+=S[i].score[j]; }}qsort(S,115,sizeof(struct stu),comp);for(i=0;i<119;i++) fout<<S[i].num<<S[i].total;return 0;}......

阅读全文(4646) | 评论:2

C++吧第二界编程大赛.(2005-11-23 16:55:00)

摘要:本次有2道题目: 1.  2个月后。输入一个日期(YYYY-MM-DD),输出2个月后的日期。 测试数据: input:2005-11-212005-07-31 output:2006-01-212005-09-30   2.有人预测计算机每10年更新一代。比如现在的计算机是32进制,2006后可能就更新为64进制.如:1986-1996 16进制.    1996-2006 32进制.    2006-2016 64进制......16进制计算机能表达的最大的一个数的阶层为8  (2^16=65536 8!=40320 9!=362880   8!<2^16<9!)本程序输入一个年份(小于2106),输出这年计算机能表示的最大的数的阶层。 测试数据: input:19812005 output:812 注意: 编程语言C/C++ ......

阅读全文(4840) | 评论:4

C++吧第一界编程大赛(其它人算法) (2005-11-10 19:08:00)

摘要:网友222.70.181.*     #include<iostream> using namespace std; bool IsUglyNum( int nNum, int* pNum, int nCur ); int CalUglyNum( int nIndex ) {  if( nIndex > 4 )  {  int *pNum;  int nCur = 3;    pNum = new int[ nIndex ];  int nNum = 6;  pNum[ 0 ] = 2;  pNum[ 1 ] = 3;  pNum[ 2 ] = 4;  pNum[ 3 ] = 5;  bool bContinue = true;  for( int nCount = 4; nCount < nIndex; )  {  while( bContinue )  {  if( IsUglyNum( nNum, pNum, nCur ) )  {  pNum[ ++nCur ] = nNum;  nCount++;  nNum++;  bContinue = false;  }  else  nNum++;  }  bContinue = true;  } delete []pNum; return --nNum;  }  else  {  switch( nIndex )  {  case 1:  return 2;  case 2:  return 3;  case 3:  return 4;  case 4:  return 5;  default:  return 0;  }  } } bool IsUglyNum( int nNum,......

阅读全文(4728) | 评论:0

C++吧第一界编程大赛(算法二)(2005-11-10 18:45:00)

摘要:#include<iostream.h> int main(){ int n,n1,m,sum,flag; while(cin>>n) {  n--;  n1=2;  sum=0;  while(n>sum)  {   m=n1;   flag=0;   while(m%2==0)    m=m/2;   while(m%3==0)    m=m/3;   while(m%5==0)    m=m/5;   if(m==1)    flag=1;   if(flag==1)    sum++;   n1++;  }  cout<<n1-1<<endl; }}......

阅读全文(4556) | 评论:0

C++吧第一界编程大赛(算法一)(2005-11-09 20:14:00)

摘要:#include <iostream.h>int min(int a,int b){if(a>b) a=b;return a;} int main(){int a[200];int p1,p2,p3;int n,i;while(cin>>n){a[0]=1;p1=p2=p3=0;for(i=1;i<n;i++){a[i]=min(a[p1]*2,min(a[p2]*3,a[p3]*5));if(a[p1]*2==a[i])p1++;if(a[p2]*3==a[i])p2++;if(a[p3]*5==a[i])p3++;}cout<<a[n-1]<<endl;}return 0;}......

阅读全文(5099) | 评论:0

C++吧第一界编程大赛(2005-11-09 20:10:00)

摘要:Ugly Numbers 题目描述: Ugly Numbers就是主要因数为2,3,5的数字. 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ...  上面显示的是前11个Ugly Numbers. 要求写一个程序输出第n个Ugly Numbers 测试数据: input: 2  99  output: 2 1500 注意: 输入数据的范围为1~200 编程语言C/C++ ......

阅读全文(5005) | 评论:0

C程序(2005-10-28 21:27:00)

摘要:main() {int i,j; for(i=1;i<10;i++) for(j=1;j<i+1;j++) printf((j==i)?"%d*%d=%-2d\n":"%d*%d=%-2d ",j,i,i*j); } ......

阅读全文(3098) | 评论:3

百度C语言吧-问题资料大全(2005-10-22 15:26:00)

摘要:1 【 C 语言吧 · 问题资料大全 】   注意: 1.这里会尽量搜集所有问题,定时更新,有问题请先查阅这里. 2.为方便查阅,请不要在此问问题,此类贴将被删除,不另通知. 3.希望这里成为大家学习 C 的好帮手. 2 ■■■■■■■____本吧相关____■■■■■■■  ★本吧推荐的几个C编译器:http://post.baidu.com/f?kz=2769360 ◆本吧代码格式编辑器:http://post.baidu.com/f?kz=9364381 ◆本吧代码中显示?:http://post.baidu.com/f?kz=5054984 4 ■■■■■■■____学习资料____■■■■■■■  ◆搜索答案与提问的秘诀:http://post.baidu.com/f?kz=6602487 ◆C 语言学习看什么书:http://post.baidu.com/f?kz=5728013 ◆如何学好c语言:http://post.baidu.com/f?kz=8642778  ◆学 C 容易出错的地方: http://post.baidu.com/f?kz=4275539  ◆C程序易犯错误:http://post.baidu.com/f?kz=12428951 ◆几种排序算法:http://post.baidu.com/f?kz=5633380 ◆几个经典字符串Hash函数:http://post.baidu.com/f?kz=5662514  ◆100,000素数表:http://post.baidu.com/f?kz=5663116 ◆C99 的语言新特性:http://post.baidu.com/f?kz=4784366 ◆深入理解C语言指针的奥秘:http://post.baidu.com/f?kz=5932198 ◆ISO-c99标准英文全文(pdf格式):http://www.nirvani.net/docs/ ◆C 的文件操作:http://post.baidu.com/f?kz=5877273 ◆字符屏幕函数:http://post.baidu.com/f?kz=6001621 ◆C的运算符:http://post.baidu.com/f?kz=8512815 ◆图......

阅读全文(7624) | 评论:7