zoukankan      html  css  js  c++  java
  • 五、PTA实验作业(结构体)

    1、提交列表

    2、设计思路就是设计一个类似于在数组里面求最低和最大数值的函数

    最终代码如下:

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    typedef struct Node{
        char s[35];
        double price;
    }Node;
    bool cmp(Node a, Node b){
        return a.price<b.price;
    }
    int main(){
        int n;
        Node t[15];
        cin>>n;
        getchar();
        for(int i = 0;i<n;i++){
            gets(t[i].s);
            cin>>t[i].price;
            getchar();
        }
        sort(t,t+n,cmp);
        printf("%.2lf, %s
    ",t[n-1].price,t[n-1].s);
        printf("%.2lf, %s
    ",t[0].price,t[0].s);
        return 0;
    }


     

     

    题目二:

    1、提交列表

    2、设计思路(包括流程图)

     最终代码如下:

    #include<stdio.h>  
    #include<stdlib.h>  
    #include<string.h>  
      
      
    struct list{  
        char name[11];  
        char num[17];  
        char phone[17];  
        char sex[2];
        char birthday[11];  
    };  
    struct list p[100];  
      
      
    int main()  
    {  
      
    int i=0;int j=0,N,K;  
    scanf("%d",&N);  
    for(i=0;i<N;i++)  
    {  
    scanf("%s %s %c %s %s
    ",&p[i].name,&p[i].birthday,&p[i].sex,&p[i].num,&p[i].phone);  
    }  
      
      
        scanf ("%d", &K);  
          
        int number;   
        for (i=0; i<K; i++) {  
            scanf ("%d", &number);  
            if (number < N && number>=0)   
            {  
               printf("%s %s %s %s %s
    ",p[number].name,p[number].num,p[number].phone,p[number].sex,p[number].birthday);    
            } else {  
                printf ("Not Found
    ");   
            }  
        }  
        return 0;  
      
    }  

     

    题目三:

    1、提交列表

    2. 设计思路(包括流程图)

    就是从高到低的顺序来进行配对,高分的0对应低分的1,高分的1对应低分的0;由数组的先后顺序来间接表示分数顺序。

     最终代码如下:

    #include<stdio.h>
    #include<math.h>
    #include<string.h>
    #include<memory.h>
    struct node{
      int a;
      char name[9];
    }p[50];
    int main()
    {
    
         int n;
         scanf("%d", &n);
         int flag;
         for(int i = 0; i < n ;i++)
           {
           scanf("%d %s", &p[i].a, p[i].name);
           }
        for(int i = 0; i < n/2; i++)
        {
        flag = 0;
            printf("%s", p[i].name);
            if(p[i].a == 0)
            {
               for(int j = n-1; j >= n/2; j--)
               {
                  if(p[j].a == 1&&p[j].a!= 2)
                  {
                     printf(" %s
    ",p[j].name);
                     p[j].a = 2;
                     flag = 1;
                  }
                  if(flag == 1)
                  break;
               }
            }
            else if(p[i].a == 1)
            {
                for(int j = n-1; j >= n/2; j--)
               {
                  if(p[j].a == 0&&p[j].a!= 2)
                  {
                     printf(" %s
    ",p[j].name);
                     p[j].a = 2;
                     flag = 1;
                  }
                  if(flag == 1)
                  break;
               }
            }
        }
           return 0;
    }

     三、截图本周题目集的PTA最后排名。

  • 相关阅读:
    实现可重启线程
    让别人能登陆你的mysql
    zmq消息订阅
    git备忘
    【LeetCode】数组排列问题(permutations)(附加next_permutation解析)
    【LeetCode】 数相加组合 Combination Sum
    【LeetCode】【找元素】Find First and Last Position of Element in Sorted Array
    【LeetCode】【数组归并】Merge k Sorted Lists
    【LeetCode】【动态规划】Generate Parentheses(括号匹配问题)
    【Leetcode】Remove Nth Node From End of List
  • 原文地址:https://www.cnblogs.com/LSCOOLYI/p/8320508.html
Copyright © 2011-2022 走看看