ToB企服应用市场:ToB评测及商务社交产业平台

标题: 1052 Linked List Sorting 25 [打印本页]

作者: 滴水恩情    时间: 2024-12-6 15:42
标题: 1052 Linked List Sorting 25
 


  1. #include <cstdio>
  2. #include <algorithm>
  3. using namespace std;
  4. const int maxn = 100005;
  5. struct Node{
  6.     int address,data,next,flag;
  7. }nodes[maxn];
  8. bool cmp(Node a, Node b){
  9.     if(a.flag != b.flag) return a.flag > b.flag;
  10.     else return a.data < b.data;
  11. }
  12. int main() {
  13.     int n,head;
  14.     scanf("%d%d", &n, &head);
  15.     int tmp;
  16.     for(int i = 0; i < n; i++){
  17.         scanf("%d", &tmp);
  18.         scanf("%d%d", &nodes[tmp].data, &nodes[tmp].next);
  19.         nodes[tmp].address = tmp;
  20.         nodes[tmp].flag = 0;
  21.     }
  22.     int valid = 0;
  23.     int cur;
  24.     for(cur = head; cur != -1; cur=nodes[cur].next){
  25.         valid++;
  26.         nodes[cur].flag = 1;
  27.     }
  28.     if(valid == 0){
  29.         printf("0 -1\n");
  30.         return 0;
  31.     }
  32.     sort(nodes, nodes+maxn, cmp);
  33.     printf("%d %05d\n", valid, nodes[0].address);
  34.     for(int i = 0; i < valid; i++){
  35.         if(i != valid - 1){
  36.             printf("%05d %d %05d\n", nodes[i].address, nodes[i].data, nodes[i+1].address);
  37.         }else{
  38.             printf("%05d %d -1\n", nodes[i].address, nodes[i].data);
  39.         }
  40.     }
  41.     return 0;
  42. }
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4