AOJ. 数组训练.2016-11-17

A题

#include <stdio.h>
#include <stdlib.h>
#define max 1000
__int64 a[max] = {0,1,1};
int main()
{
    int i,n;
     scanf("%d",&n);

    for(i = 3;i<=n;i++){
        a[i] = a[i-1]+a[i-2];

    }
//printf("%d",a[5]);

    for(i = n;i>=1;--i){
        printf("%I64d\n",a[i]);
    }
    return 0;
}

B题

#include <stdio.h>
#include <stdlib.h>
#define max 1001
__int64 a[max];

int main()
{
    int n,i,j;
    __int64 t;
    int flag = 0;
    //scanf("%d",&n);
    for(i = 0;i<10;i++){
        scanf("%I64d",&a[i]);
    }
    for(i = 0;i<10-1;i++){
        for(j = 0;j<10-i-1;j++){
            if(a[j]>a[j+1]){
                t = a[j+1];
                a[j+1] = a[j];
                a[j] = t;
            }
        }
    }

    for(i = 0;i<10;++i){
        if(!flag){
            printf("%I64d",a[i]);
            flag = 1;
        }else{
            printf(" %I64d",a[i]);
        }
    }
    printf("\n");
    return 0;
}

C题

#include <stdio.h>
#include <stdlib.h>
#define ma 55
int a[ma][ma],max[ma],min[ma];

int main()
{
    //freopen("in.txt","r",stdin);
    int i,j,n,m,judge=0,k=0;
    scanf("%d%d",&n,&m);
    for(i = 0;i<n;++i){
        for(j = 0;j<m;++j){
            scanf("%d",&a[i][j]);

        }
    }
    for(i = 0;i<n;i++){
        max[i] = a[i][0];
    }
    for(i = 0;i<m;++i){
        min[i] = a[0][i];
    }
    for(i = 0;i<n;++i){
        for(j = 0;j<m;++j){
            if(a[i][j]>max[i]){
                max[i] = a[i][j];
            }
            if(a[i][j]<min[j]){
                min[j] = a[i][j];
            }
        }
    }
    for(i = 0;i<n;i++){
        for(j = 0;j<m;j++){
            if(max[i] == min[j]){
                judge = 1;
                printf("%d %d %d\n",i,j,a[i][j]);
                break;
            }
        }
        if(judge){
            break;
        }
    }
    if(!judge){
        printf("It does not exist!\n");
    }
    return 0;
    //fclose(stdin);
}

D题

#include <stdio.h>
#include <stdlib.h>
#define max 50
int a[max][max]={0};
int b[max][max]={0};
int main()
{
    int n,i,j,k,flag = 0;
    scanf("%d",&n);
    for(i = 0;i<n;i++){
        for(j = 0;j<=i;j++){
            if(j==i || !j ){
                a[i][j] = 1;
            }else{
                a[i][j] = a[i-1][j-1]+a[i-1][j];
            }
        }
    }
    //for(i = 0;i<n;i++){
    //    for(j = 0;j<=i;j++){
    //       printf(" %d",a[i][j]);
    //    }
    //    printf("\n");
    //}

    for(i = 0;i<n;i++){
        for(j = 0,k = i-j;j<=i;j++,k--){
            b[j][k] = a[i][j];
        }
    }
    for(i = 0;i<n;i++){
        flag = 0;
        for(j = 0;j<n-i;j++){
            if(flag == 0){
                printf("%d",b[i][j]);
                flag = 1;
            }else{
                printf(" %d",b[i][j]);
            }
        }
        printf("\n");
    }
    return 0;
}

E题

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define max 10001
char str[max],substr[20],substr1[20];
int main()
{
    //freopen("in.txt","r",stdin);
    int len,i,j,wordlen1,len2,now;
    while(gets(str)){
        now = wordlen1 = 0;
        len = strlen(str);
        //memset(str,'\0',sizeof(str));
        //memset(substr,'\0',sizeof(substr));
        for(i = 0,j = 0;i<=len;++i){
            if(str[i] == ' '||str[i] == '\0'){
                wordlen1 = i-j;
                int k;
                for(k = 0;k<wordlen1;k++,j++){
                        substr1[k] = str[j];
                    }
                    j = i+1;
                    if(wordlen1 >now){
                memcpy(substr,substr1,wordlen1);
                now = wordlen1;
            }else if(wordlen1 == now){
                if(strcmp(substr1,substr)<0){
                    memcpy(substr,substr1,wordlen1);
                }
            }
            }



        }
        //for(i = 0;i<now;++i){
        //    printf("%c",&substr[i]);
        //}
        printf("%s\n",substr);
        for(i = 0;i<len;++i){
            str[i] = '\0';
            substr[i] = '\0';
        }
    }
    return 0;
    //fclose(stdin);
}

F题

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max 10001
char str[max];

int main()
{
    int len,i,judge;
    while(scanf("%s",str)!=EOF){
        judge = 0;
        len = strlen(str);
       // printf("%d\n",len);
        for(i = 0;i<=len/2;++i){
            if(str[i]!=str[len-i-1]){
               // printf("%c %c\n",str[i],str[len-i-1]);
                judge = 1;
                break;
            }
        }
        if(judge){
            printf("NO\n");
        }else{
            printf("YES\n");
        }
    }
    return 0;
}

posted @ 2016-11-17 18:06  pengwill  阅读(123)  评论(0编辑  收藏  举报