mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
commit
472a46b4a2
37
QUSTOJ/1715.c
Normal file
37
QUSTOJ/1715.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
/// itoa implement
|
||||
char* int2str(int num,char* buff,int bina)
|
||||
{
|
||||
char k[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
|
||||
if(bina==10)
|
||||
{
|
||||
sprintf(buff,"%d",num);
|
||||
return buff;
|
||||
}
|
||||
int cnt=0;
|
||||
while(num>0)
|
||||
{
|
||||
buff[cnt]=k[num%bina];
|
||||
num=num/bina;
|
||||
cnt++;
|
||||
}
|
||||
buff[cnt]=0;
|
||||
for(int i=0;i<cnt/2;i++)
|
||||
{
|
||||
char t=buff[i];
|
||||
buff[i]=buff[cnt-i-1];
|
||||
buff[cnt-i-1]=t;
|
||||
}
|
||||
return buff;
|
||||
}
|
||||
|
||||
char buff[32];
|
||||
int a,b;
|
||||
int main()
|
||||
{
|
||||
scanf("%d %d",&a,&b);
|
||||
printf("%s\n",int2str(a,buff,b));
|
||||
return 0;
|
||||
}
|
41
QUSTOJ/1716.c
Normal file
41
QUSTOJ/1716.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int cmp(const void* a,const void* b)
|
||||
{
|
||||
return *((int*)b)-*((int*)a);
|
||||
}
|
||||
|
||||
int p[1024];
|
||||
|
||||
int main()
|
||||
{
|
||||
int n,target;
|
||||
scanf("%d%d",&target,&n);
|
||||
for(int i=0;i<n;i++)
|
||||
{
|
||||
scanf("%d",&p[i]);
|
||||
}
|
||||
qsort(p,n,sizeof(int),cmp);
|
||||
int found=0;
|
||||
for(int i=0;i<n;i++)
|
||||
{
|
||||
printf("%d ",p[i]);
|
||||
}
|
||||
printf("\n");
|
||||
for(int i=0;i<n;i++)
|
||||
{
|
||||
if(p[i]==target)
|
||||
{
|
||||
printf("%d\n",i+1);
|
||||
found=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!found)
|
||||
{
|
||||
printf("-1\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
23
QUSTOJ/1717.c
Normal file
23
QUSTOJ/1717.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#define MAXN 256
|
||||
int bucket[MAXN];
|
||||
|
||||
int main()
|
||||
{
|
||||
int t;
|
||||
scanf("%d",&t);
|
||||
int tmp;
|
||||
for(int i=0;i<t;i++)
|
||||
{
|
||||
scanf("%d",&tmp);
|
||||
if(bucket[tmp]==0)
|
||||
{
|
||||
++bucket[tmp];
|
||||
printf("%d ",tmp);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
36
QUSTOJ/1718.c
Normal file
36
QUSTOJ/1718.c
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int dx[32][32];
|
||||
|
||||
#define MAXN 20
|
||||
|
||||
void calc()
|
||||
{
|
||||
dx[1][1]=1;
|
||||
for(int i=2;i<=MAXN;i++)
|
||||
{
|
||||
for(int j=1;j<=i;j++)
|
||||
{
|
||||
dx[i][j]=dx[i-1][j-1]+dx[i-1][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
calc();
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
for(int i=1;i<=n;i++)
|
||||
{
|
||||
for(int j=1;j<=i;j++)
|
||||
{
|
||||
printf("%d ",dx[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
19
QUSTOJ/1719_****090114.c
Normal file
19
QUSTOJ/1719_****090114.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include<stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int x,i,j,k;
|
||||
scanf("%d",&x);
|
||||
for(i=1;i<=x;++i)
|
||||
{
|
||||
for(j=i;j<=x;++j)
|
||||
for(k=j;k<=x;++k)
|
||||
{
|
||||
if(i*i+j*j==k*k)
|
||||
printf("%d %d %d\n",i ,j ,k);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
28
QUSTOJ/1720.c
Normal file
28
QUSTOJ/1720.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char buff[64];
|
||||
|
||||
int cnt[10];
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
for(int i=1;i<=n;i++)
|
||||
{
|
||||
sprintf(buff,"%d",i);
|
||||
int len=strlen(buff);
|
||||
for(int j=0;j<len;j++)
|
||||
{
|
||||
++cnt[buff[j]-'0'];
|
||||
}
|
||||
}
|
||||
for(int i=0;i<9;i++)
|
||||
{
|
||||
printf("%d ",cnt[i]);
|
||||
}
|
||||
printf("%d\n",cnt[9]);
|
||||
return 0;
|
||||
}
|
37
QUSTOJ/1721.c
Normal file
37
QUSTOJ/1721.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
//Written by Kiritow. 求最大公约数
|
||||
long gcd(long a,long b)
|
||||
{
|
||||
if(a==0||b==0)
|
||||
{
|
||||
if(a+b==0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return (a==0)?b:a;
|
||||
}
|
||||
|
||||
while(a!=b)
|
||||
{
|
||||
if(a>b)
|
||||
{
|
||||
a=a-b;
|
||||
}
|
||||
else
|
||||
{
|
||||
b=b-a;
|
||||
}
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int a,b;
|
||||
scanf("%d%d",&a,&b);
|
||||
int ans=gcd(a,b);
|
||||
printf("%d\n%d\n",ans,a*b/ans);
|
||||
return 0;
|
||||
}
|
23
QUSTOJ/1723.c
Normal file
23
QUSTOJ/1723.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
char buff[32];
|
||||
int main()
|
||||
{
|
||||
int a,b;
|
||||
scanf("%d,%d",&a,&b);
|
||||
int tmp;
|
||||
int ans=0;
|
||||
for(int i=1;i<=b;i++)
|
||||
{
|
||||
for(int j=1;j<=i;j++)
|
||||
{
|
||||
buff[j-1]='0'+a;
|
||||
}
|
||||
buff[i]=0;
|
||||
sscanf(buff,"%d",&tmp);
|
||||
ans+=tmp;
|
||||
}
|
||||
printf("a=%d,b=%d\n%d\n",a,b,ans);
|
||||
return 0;
|
||||
}
|
34
QUSTOJ/1724.c
Normal file
34
QUSTOJ/1724.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define DUR 0.001
|
||||
double func(double x)
|
||||
{
|
||||
return (2*x*x*x)-(4*x*x)+3*x-6;
|
||||
}
|
||||
|
||||
double dfs(double L, double Mid, double R)
|
||||
{
|
||||
int t;
|
||||
if(R-L < DUR) return R;
|
||||
|
||||
if(func(L)*func(Mid) <=0)
|
||||
{
|
||||
t= dfs(L,(L+Mid)/2,Mid);
|
||||
}
|
||||
else if(func(Mid)*func(R) <=0)
|
||||
{
|
||||
t= dfs(Mid,(Mid+R)/2,R);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
double a, b, c;
|
||||
scanf("%lf,%lf",&a,&c);
|
||||
b = (a+c)/2;
|
||||
printf("x=%6.2f\n",dfs(a,b,c));
|
||||
return 0;
|
||||
}
|
10
QUSTOJ/1725.c
Normal file
10
QUSTOJ/1725.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("0\t25\t75\n4\t18\t78\n8\t11\t81\n12\t4\t84\n");
|
||||
return 0;
|
||||
}
|
||||
|
13
QUSTOJ/1725_****090114.c
Normal file
13
QUSTOJ/1725_****090114.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
int g,m,c;
|
||||
for(g=0;g<21;++g)
|
||||
for(m=0;m<35;m++)
|
||||
for(c=0;c<100;c+=3)
|
||||
if(g*5+m*3+c/3==100&&g+m+c==100)
|
||||
printf("%d\t%d\t%d\n",g,m,c);
|
||||
return 0;
|
||||
}
|
28
QUSTOJ/1726.c
Normal file
28
QUSTOJ/1726.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int cnt=0;
|
||||
int cash;
|
||||
scanf("%d",&cash);
|
||||
int amax=cash/5;
|
||||
int bmax=cash/2;
|
||||
int cmax=cash;
|
||||
for(int a=1;a<=amax;a++)
|
||||
{
|
||||
for(int b=1;b<=bmax;b++)
|
||||
{
|
||||
for(int c=1;c<=cmax;c++)
|
||||
{
|
||||
if(5*a+2*b+c==cash)
|
||||
{
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("%d\n",cnt);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user