摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 int is_prime(int x) 5 { 6 int i; 7 if(x==1) return 1;//是素数返回0,不是素数返回1 8 for(i=2;i<=sqrt(x);i++) 9 if(x%i==0) return 1;10 return 0;11 }12 int main()13 {14 int n,m,a,b;15 scanf("%d",&n);16 while(n--)17 ...
阅读全文
摘要:地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=204 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 int main() 5 { 6 int i,N,k,t,m,n,a,b; 7 char s[65536]; 8 scanf("%d",&N); 9 getchar();10 gets(s);11 for(a=b=i=0;i<N;i++)12 {13 if(s[i]=='U')
阅读全文
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 int T,i,j,t,sum; 6 char s1[11],s2[11];//用字符数组表示,最大11位,使用方便 7 scanf("%d",&T); 8 while(T--) 9 {10 scanf("%s %s",s1,s2);11 for(sum=i=0;s1[i]!='\0';i++)12 {13 for(t=j=0;s2[j]!='\0';j++)14...
阅读全文
摘要:由于是pow函数返回的是浮点型,此处不行,考虑到long long int 1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 int x,n,i; 6 long long int s; 7 while(scanf("%d%d",&x,&n)!=EOF) 8 { 9 s=1;10 for(i=0;i<n;i++)11 {12 s=s*x;13 }14 printf("%lld\n",s);15...
阅读全文
摘要:地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=85法一: 1 #include<stdio.h> 2 int main() 3 { 4 int i,k,m,n; 5 scanf("%d",&m); 6 while(m--) 7 { 8 scanf("%d",&n); 9 for(i=1;i*(i+1)>>1<n;i++);10 k=n-(i*(i-1)>>1);11 if(i&1)12 printf("%d/%d\n&qu
阅读全文
摘要:地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=102 1 //a^b mod c=(a mod c)^b mod c很容易设计出一个基于二分的递归算法。 2 #include<stdio.h> 3 #include<stdlib.h> 4 //快速幂算法,数论二分 5 long long powermod(int a,int b, int c) //不用longlong就报错,题目中那个取值范围不就在2的31次方内 6 { 7 long long t; 8 if(b==0) return 1%c; 9 if(..
阅读全文
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 int m,n,s; 6 scanf("%d",&m); 7 while(m--) 8 { 9 scanf("%d",&n);10 s=0;11 while(n!=1)12 {13 s++;14 if(n&1) s++;15 n/=2;16 }17 printf("%d\n"...
阅读全文
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 int n,i,j; 6 int a[3][3]; 7 scanf("%d",&n); 8 while(n--) 9 {10 for(i=0;i<3;i++)11 for(j=0;j<3;j++)12 scanf("%d",&a[i][j]);13 for(i=0;i<3;i++)14 {15 for(j=0;j<3;j++)16 ...
阅读全文
摘要:1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 int cmp(const void *a,const void *b) 5 { 6 return *(int *)a-*(int *)b; 7 } 8 int main() 9 {10 int t,m,n,i;11 int a[11000];12 scanf("%d",&t);13 while(t--)14 {15 scanf("%d",&m);16 memset(a,0,s
阅读全文
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define Stack_Size 100 4 #define StackIncrement 10 5 #define Ok 1 6 #define Error 0 7 #define True 1 8 #define False 0 9 #define Overflow -2 10 typedef int status; 11 //字符栈的操作 12 typedef struct 13 { 14 char *base; 15 char *top; 16 int stacks...
阅读全文
摘要:1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #define N 501 5 char a[N]; 6 double fun() 7 { 8 int len; 9 char ch[10];10 sscanf(a,"%s",ch);//以字符串读入到ch11 len=strlen(ch);12 strcpy(a,a+len);13 switch(ch[0])14 {15 case '+': return fun()+fun();16 ...
阅读全文
摘要:法一: 1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 int d,i,k; 6 while(~scanf("%d%d",&d,&i)&&(d||i)) 7 { 8 k=1; 9 while(--d)10 {11 if(i&1)12 {k*=2; i=(i+1)/2;}13 else14 {k=2*k+1; i/=2;}15 }16...
阅读全文
摘要:法一: 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 //这个表达式求值,要先算最小单元的数值,可以采用递归方式 5 char str[350];//使用全局数据保存字符串 6 int first;//字符当前位置 7 int min(int x,int y) 8 { 9 return x>y ? y:x;//返回比较小的数10 }11 int max(int x,int y)12 {13 return x>y ? x:y;//返回比较大的数14 }15 int f
阅读全文
摘要:1 #include <iostream> 2 #include<cstdio> 3 #include <string> 4 using namespace std; 5 struct Node{ 6 char data; 7 Node* lchild; 8 Node* rchild; 9 };10 Node* CreateTree(string pre,string in)11 {12 Node* root = NULL;13 if(pre.length()>0)14 {15 root = new Node;16 ...
阅读全文
摘要:1 #include<stdio.h> 2 #include<math.h> 3 int main() 4 { 5 int i,m,n,k,t; 6 scanf("%d",&n); 7 while(n--) 8 { 9 scanf("%d",&m);10 t=sqrt(m+1);11 for(i=2,k=0;i<=t;i++)12 if((m+1)%i==0)13 k++;14 printf("%d\n",k);15 }16 return 0;17 ...
阅读全文
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 #define N 1010 4 char s[N]; 5 //字符栈的操作 6 typedef struct 7 { 8 char *base; 9 char *top; 10 }SqStack1; 11 int InitStack1(SqStack1 &S) 12 { 13 S.base=(char *)malloc(N*sizeof(char)); 14 if(!S.base) exit(1); 15 S.top=S.ba...
阅读全文
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int i,j,m,t,N; 5 unsigned a[1010][3]; 6 scanf("%d",&N); 7 while(N--) 8 { 9 scanf("%d",&m);10 for(i=1;i<=m;i++)11 for(j=0;j<3;j++)12 scanf("%ld",&a[i][j]);13 for(i=1,a[0][0]=0;i<=m;i++)14 if(a[...
阅读全文
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 char operand; 6 int a,b,c,d,e,f,flag,end; 7 while(scanf("%d/%d%c%d/%d",&a,&b,&operand,&c,&d)!=EOF) 8 { 9 if(operand=='+') //e为分子,f为分母 10 e=a*d+b*c;11 else12 e=a*d-b*c;13 f=b*d;14 ...
阅读全文
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int n,k,N,s; 5 scanf("%d",&N); 6 while(N--) 7 { 8 scanf("%d%d",&n,&k); 9 for(s=n;n>=k;n=n/k+n%k)10 s+=n/k;11 printf("%d\n",s);12 }13 return 0;14 }15
阅读全文
摘要:1 #include<stdio.h> 2 int main() 3 { 4 int N,M,x,y,z; 5 scanf("%d",&N); 6 while(N--) 7 { 8 scanf("%d%d%d%d",&M,&x,&y,&z); 9 printf("%.2f\n",z*((float)(M*x)/(y-x)));10 }11 return 0;12 }
阅读全文