2、求超级的特定位的值
求高次方,比如13的13次方的后三位
主要算法代码
x的y次方后n位,有些数是电脑无法表示的:
for(int i=1; i<y; i++)
x=x*x%(10^n)
遇到取最大值,最小值:
max=-32768; /*先假设当前的最大值max为C语言整型数的最小值*/
min=32767; /*先假设当前的最小值min为C语言整型数的最大值*/
尾数有多少个零的算法
因数里面因数有5、25、125。。。分别为1个0,2个零等
比如100!尾数有多少个零
for(i=5;i<=100;i+=5)
{
++count;
if(!(i%25)) count++;
}
3、日期操作
主要掌握如何计算从以前某一时候到后面任意时刻的天数,这样可以应对很多这方面的关于日期的问题。
打印日历:
经过一早上的努力,终于完美地实现打印日历了;
显示1970年之后的任意一年的日历(公历)
#include <iostream>
#include <string.h>
using namespace std;
struct date
{
int year;
int month;
int day;
int lp;
};
int days (struct date day);
void weekday(int n);
int main()
{
struct date term;
int year=1969;
bool output=true;
int n=0,start;
int day_tab[2][12]=
{{31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,31,30,31,30,31}};
string mon[12]={"January","February","March","April","May","June","July","August","September","October","November","December"};
cout<<"||==========+++++++++++==========||"<<endl;
cout<<"|| Calendar(from 1970) ||"<<endl;
cout<<"|| created by Dick_zh ||"<<endl;
cout<<"||==========+++++++++++==========||"<<endl<<endl;
cout<<"input the year:"<<endl;
while(year<1970)
cin>>year;
term.month=12;
term.day=0;
for(int i=1970;i<year;i++)
{
term.year=i;
term.lp=i%4==0&&i%100!=0||i%400==0;
n+=days(term);
}
start=n%7+4;
term.year=year;
term.lp=year%4==0&&year%100!=0||year%400==0;
for(int j=0;j<term.month;j++)
{
cout<<mon[j]<<":"<<endl;
for(int k=1,l=1;k<=day_tab[term.lp][j]||l<=day_tab[term.lp][j];)
{
if(output)
{
if(k>day_tab[term.lp][j])
{
cout<<endl;
output=false;
continue;
}
weekday(start%7);
start++;
cout<<" ";
if(k%7==0)
{
cout<<endl;
output=false;
}
k++;
}
else if(!output)
{
if(l<10)
cout<<" "<<l<<" ";
else if(l>=10)
cout<<" "<<l<<" ";
if(l%7==0)
{
cout<<endl;
output=true;
}
l++;
}
}
output=true;
cout<<endl<<endl;
}
return 0;
}
int days(date day)
{
int day_tab[2][12]=
{{31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,31,30,31,30,31}};
for(int i=0;i<day.month;i++)
day.day+=day_tab[day.lp][i];
return day.day;
}
void weekday(int n)
{
switch(n)
{
case 0:cout<<"Sunday";break;
case 1: cout<<"Monday";break;
case 2:cout<<"Tuesday";break;
case 3:cout<<"Wednesday";break;
case 4:cout<<"Thursday";break;
case 5:cout<<"Friday";break;
case 6:cout<<"Saturday";break;
}
}