杭电oj2032、2040、2042、2054、2055
2032 杨辉三角
1 #include <stdio.h> 2 3 int main(){ 4 int s[31][31],i,j,n; 5 while(~scanf("%d",&n)){ 6 for(i=0;i<n;i++){ 7 for(j=0;j<=i;j++){ 8 if(j==0 || j==i){s[i][j]=1;} 9 else{s[i][j]=s[i-1][j]+s[i-1][j-1];} 10 } 11 } 12 for(i=0;i<n;i++){ 13 for(j=0;j<=i;j++){ 14 if(j==i){printf("%d\n",s[i][j]);} 15 else{printf("%d ",s[i][j]);} 16 } 17 } 18 printf("\n"); 19 } 20 }
2040 亲和数
1 #include <stdio.h> 2 3 int qhs(int a){ 4 int i,j,sum,s[50]; 5 s[0]=1;j=1; 6 for(i=2;i<=a/2;i++){ 7 if(a%i==0){s[j]=i;j++;} 8 } 9 sum=0; 10 for(i=0;i<j;i++){sum += s[i];} 11 return sum; 12 } 13 14 int main(){ 15 int n,i,a,b,c,s[100]; 16 while(scanf("%d",&n)!=EOF){ 17 while(n--){ 18 scanf("%d %d",&a,&b); 19 if(qhs(a)==b || qhs(b)==a){printf("YES\n");} 20 else{printf("NO\n");} 21 } 22 } 23 }
2042 不容易系列之二
1 #include <stdio.h> 2 3 int main(){ 4 int n,m,i; 5 while(scanf("%d",&n)!=EOF){ 6 while(n--){ 7 scanf("%d",&m); 8 i = 3; 9 while(m--){i = (i-1)*2;} 10 printf("%d\n",i); 11 } 12 13 } 14 }
2054 A == B ?
#include<stdio.h> #include<string.h> char a[100000],b[100000]; void change(char s[]) { int len,i; len=strlen(s); if(strstr(s,".")) { for(i=len-1;s[i]=='0';i--) { s[i]='\0'; len--; } } if(s[len-1]=='.') s[len-1]='\0'; } int main() { while(~scanf("%s %s",&a,&b)) { change(a); change(b); if(strcmp(a,b)==0) printf("YES\n"); else printf("NO\n"); } return 0; }
2055 An easy problem
1 #include <stdio.h> 2 #include <string.h> 3 4 int f(char a){ 5 if(a>='A'&&a<='Z'){return a-64;} 6 if(a>='a'&&a<='z'){return 96-a;} 7 } 8 9 int main(){ 10 char a; 11 int n,b,sum; 12 while(scanf("%d",&n)!=EOF){ 13 getchar(); 14 while(n--){ 15 16 scanf("%c %d",&a,&b); 17 getchar(); 18 sum = b + f(a); 19 printf("%d\n",sum); 20 21 } 22 } 23 }