• PAT 1073


    链接:http://www.patest.cn/contests/pat-a-practise/1073

    明天就考试了,圆神保佑萌萌哒~

    scientific notation,科学记数法,分几种情况进行判断,主要是exponent的部分,如果exponent小于0的话,需要在前面添加0,如果exponent大于0的话,可能在后面添加0.想清楚了不难的。

     1 #include <fstream>
     2 #include <iostream>
     3 #include <vector>
     4 #include <string>
     5 #include <stack>
     6 
     7 using namespace std;
     8 
     9 //#define OJ
    10 
    11 #ifdef OJ
    12 #define fin cin
    13 #else
    14 ifstream fin("in.txt");
    15 #endif
    16 
    17 struct Node{
    18     int cur_address;
    19     int val;
    20     int next_address;
    21 };
    22 
    23 int main(){
    24     string start;
    25     int    n, k;
    26     fin >> start >> n >> k;
    27 
    28     vector<Node> nodes(100000);
    29 
    30     for (int i = 0; i < n; i++){
    31         Node tmp;
    32         string s1, s2;
    33 
    34         fin >> s1 >> tmp.val >> s2;
    35         tmp.cur_address = atoi(s1.c_str());
    36         tmp.next_address = atoi(s2.c_str());
    37 
    38         nodes[tmp.cur_address] = tmp;
    39     }
    40 
    41     int start_idx = atoi(start.c_str());
    42     int cur_address = start_idx;
    43     vector<int> path;
    44 
    45     while (start_idx != -1){
    46         path.push_back(start_idx);
    47         start_idx = nodes[start_idx].next_address;
    48     }
    49 
    50     vector<int> res;
    51     int idx = 0;
    52     n = path.size();
    53     for (; idx + k - 1 < n; idx += k){
    54         stack<int> node_stack;
    55         for (int i = 0; i < k; i++){
    56             node_stack.push(path[idx + i]);
    57         }
    58         while (!node_stack.empty()){
    59             int tmp = node_stack.top();
    60             res.push_back(tmp);
    61             node_stack.pop();
    62         }
    63     }
    64     for (; idx < n; idx++){
    65         res.push_back(path[idx]);
    66     }
    67 
    68     for (int i = 0; i < n - 1; i++){
    69         printf("%05d %d %05d
    ", nodes[res[i]].cur_address, nodes[res[i]].val, nodes[res[i + 1]].cur_address);
    70     }
    71     printf("%05d %d %d
    ", nodes[res[n - 1]].cur_address, nodes[res[n - 1]].val, -1);
    72 
    73     return 0;
    74 }
  • 相关阅读:
    bootstrap
    史上最全Html和CSS布局技巧
    三种实现左右固定,中间自适应的三栏布局方式
    网页布局常用样式属性
    去除inline-block间隙的几种方法
    HTML&CSS——使用DIV和CSS完成网站首页重构
    I want to be a Great Web Front-end Developer
    js常用函数汇总(不定期更新)
    关于git stash的应用总结
    vue 自定义指令
  • 原文地址:https://www.cnblogs.com/EpisodeXI/p/4128542.html
Copyright © 2020-2023  润新知