2031 进制转换
#define _CRT_SECURE_NO_WARNINGS 1
#include
void conversion(int n,int R)
{
if(n)//递归实现逆序输出
{
conversion(n/R,R);
printf("%c",n % R > 9 ? n % R - 10 + 'A':n % R + '0');
}
}
int main()
{
int n,R;
while(scanf("%d%d",&n,&R)!=EOF)
{
if(n>0)
conversion(n,R);
else if(n<0)
{
putchar('-');
conversion(-n,R);
}
else
putchar('0');
printf("\n");
}
return 0;
}
---------------------------------------------------
2032 杨辉三角
#define _CRT_SECURE_NO_WARNINGS 1
#include
//1
//1 1
//1 2 1
//1 3 3 1
//1 4 6 4 1
//1 5 10 10 5 1
int main()
{
int n,i,j;
int arr[30][30];
while(scanf("%d",&n)!=EOF)
{
for(i=0; i
{
for(j=0; j<=i; j++)
{
arr[i][0] = 1;//第一列
if(i==j)//对角线
{
arr[i][j] = 1;
}
else if(i>1 && j>=1)
{
arr[i][j] = arr[i-1][j] + arr[i-1][j-1];//剩下的
}
}
}
for(i=0; i
{
for(j=0; j<=i; j++)
{
printf("%d",arr[i][j]);
if(j
printf(" ");
}
putchar('\n');
}
putchar('\n');
}
return 0;
}
---------------------------------------------------
2033 人见人爱A+B
#define _CRT_SECURE_NO_WARNINGS 1
#include
typedef unsigned long UL;
int main()
{
int n;
UL AH,AM,AS,BH,BM,BS,ADD_M,ADD_H,S_TOTAL,M_TOTAL;
scanf("%d%*c",&n);
while(n--)
{
ADD_M = ADD_H = 0;
scanf("%lu%lu%lu%lu%lu%lu",&AH,&AM,&AS,&BH,&BM,&BS);
//秒
S_TOTAL = AS+BS;
if(S_TOTAL>=60)
{
AS = S_TOTAL%60;
ADD_M = S_TOTAL/60;
}
else
AS = S_TOTAL;
//分
AM = AM+ADD_M;
M_TOTAL = AM+BM;
if(M_TOTAL>=60)
{
AM = M_TOTAL%60;
ADD_H = M_TOTAL/60;
}
else
AM = M_TOTAL;
//时
AH = AH + ADD_H + BH;
printf("%lu %lu %lu\n",AH,AM,AS);
}
return 0;
}
---------------------------------------------------
2034 人见人爱A-B
#define _CRT_SECURE_NO_WARNINGS 1
#include
#include
int int_cmp(const void p1, const voidp2)
{
return *(int*)p1 - *(int*)p2;
}
int main()
{
int n,m,i,j;
int s[101];
while(scanf("%d%d",&n,&m),m+n)//一个逗号表达式
{
for(i=0; i
scanf("%d",s+i);
for(i=0;i
{
scanf("%d",s+n);//输入A集合后的第一个元素,即B的首元素
for(j=0; s[j]!=s[n]; j++)//查找A中是否存在与输入元素相等元素的下标
;
if(j!=n)
s[j] = s[--n];//如果存在,把A的最后一个元素,赋给下标对应元素,即删除该元素
}
qsort(s,n,sizeof(int),int_cmp);//将A集合从小到大规则进行比较
for(i=0; i
printf("%d ",s[i]);
printf(n ? "\n" : "NULL\n");
}
return 0;
}
---------------------------------------------------
2035 人见人爱A^B
#define _CRT_SECURE_NO_WARNINGS 1
#include
#include
typedef unsigned long UL;
int main()
{
int a,b,i;
UL temp;
while(scanf("%d%d",&a,&b),a+b)
{
temp =1;
//temp = pow((double)a,(double)b);
for(i=0; i
{
temp = (temp * a)%1000;
}
printf("%d\n",temp%1000);
}
return 0;
}
---------------------------------------------------
2036 改革春风吹满地
#define _CRT_SECURE_NO_WARNINGS 1
#include
//多边形求面积公式:
//S = 0.5 ( (x0y1-x1y0) + (x1y2-x2y1) + ... + (xny0-x0*yn) )
//其中点(x0, y0), (x1, y1), ... , (xn, yn)为多边形上按逆时针顺序的顶点。
//n个顶点就有n个多项式相加
int main()
{
int n;
int x[3],y[3];
double sum;
while(scanf("%d",&n),n)
{
scanf("%d%d",x,y);
x[2] = x[0];//存第一个顶点的值,用来计算公式最后一项
y[2] = y[0];
sum = 0.0;
while(--n)
{
scanf("%d%d",x+1,y+1);
sum += x[0]*y[1] - x[1]*y[0];
x[0] = x[1];//用输入的顶点,覆盖前一个顶点
y[0] = y[1];
}
sum += x[0]*y[2] - x[2]*y[0];//计算公式最后一项
sum = sum / 2.0;
printf("%.1f\n",sum);
}
return 0;
}
---------------------------------------------------
2037 今年暑假不AC
---------------------------------------------------
2039 三角形
#define _CRT_SECURE_NO_WARNINGS 1
#include
int main()
{
int m;
double a,b,c;
scanf("%d",&m);
while(m--)
{
scanf("%lf%lf%lf",&a,&b,&c);
if(a>0&&b>0&&c>0)
{
if(a+b>c&&a+c>b&&b+c>a)
printf("YES\n");
else
printf("NO\n");
}
else
printf("NO\n");
}
return 0;
}
---------------------------------------------------
2040 亲和数
#define _CRT_SECURE_NO_WARNINGS 1
#include
int main()
{
int n,i,num1,num2,sum1,sum2;
scanf("%d",&n);
while(n-- && scanf("%d%d",&num1,&num2))
{
sum1 = sum2 = 0;
for(i=1; i<=num1/2; i++)
{
if(num1%i==0)
sum1 += i;
}
for(i=1; i<=num2/2; i++)
{
if(num2%i==0)
sum2 += i;
}
if(sum1==num2 && sum2==num1)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
---------------------------------------------------
2041 超级楼梯
#define _CRT_SECURE_NO_WARNINGS 1
#include
int f(int x)
{
if(x==2)
return 1;
else if(x==3)
return 2;
else if(x>3)
return f(x-1)+f(x-2);
}
int main()
{
int n,m,ret;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
ret = f(m);
printf("%d\n",ret);
}
return 0;
}
--------------------------------------2
int main()
{
int n,i;
_int64 m[41] = {0,1};//防止溢出
for(i=2; i<41; i++)
{
m[i] = m[i-1] + m[i-2];
}
scanf("%d",&n);
while(n-- && scanf("%d",&i))
{
printf("%I64d\n",m[i]);
}
return 0;
}