pat还差最后4天考试

状态好差啊
写了大概两千分的题目
我需要输出点东西找找状态了,两天没怎么写题目了,话说晚上我妈回来,家里就变成燃烧瓶
不是为接下来考不好找理由啊,我的水平确实得到了提高 ,我也努力了 要是今年再没有收获 我也许会放弃走转行这条路了,拿了毕业证当个销售也许也可以。考完这次再给我四个月时间,如果没有达到顶级水准我就放弃了,必须要把放弃挂在嘴边了, 也许我会反悔 必须有压力才会学习,我的观念是这个。
剩下的题要么是天难了 太繁琐了写不动,要么时候赖堕又来了,我这两天状态低迷,只能也许可以通过输出来倒逼我写代码。
1099 Build A Binary tree
首先这题我完全能写,其次,这题很经典的套路题, 没有特别说明好说的。我的状态真的很差。

  1. 读题: 题目已经给了你二叉树的结构了 你要将这个结构搞出来,可以用数组建树也可以用个结构体数组,结构体里面用链表 形成一个树,两种方法都可以。
    然后用一个bool数组来找到根,
    题目要求你把数填到树里面,这也很好实现,
    非常经典的一个性质 就是 二叉搜索树 中序遍历排序好就是一个排序好的数
    那就中序遍历的把数填进去,先填左树再填自己再填右树

```c#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
struct Node {
    int data;
    int left;
    int right;
};
//中序遍历填树
int nums[100];
Node nodes[100];
int a = 0;
void  dfs(int cur){
    if(cur == -1){
        return;
    }
    dfs(nodes[cur].left);
    nodes[cur].data = nums[a];
    a++;
    dfs(nodes[cur].right);
}
int main(){
    int n ;
    cin>>n;
    int root = 3;
    int visit[n];
    for(int i = 0;i<n;i++){
        int left;
        int right;
        cin>>left;
        cin>>right;
         nodes[i].left = left;
        if(left != -1){
       
        visit[left] = 1;
        }
         nodes[i].right = right;
        if(right != -1){
       
        visit[right] = 1;
        }
    }
    for(int i = 0;i<n;i++){
        if(visit[i] != 1){
            root = i;
            break;
        }
    }//不是其他任何人儿子的节点是根
    for(int i = 0;i<n;i++){
        cin>>nums[i];
    }
    sort(nums,nums+n);
    int r = root;
    dfs(r); 
    // cout<<root;
    queue<int> que;
    que.push(root);
    while(!que.empty()){
        int qv = que.front();
        que.pop();
        if(nodes[qv].left != -1){
            que.push(nodes[qv].left);
        }
        if(nodes[qv].right != -1){
            que.push(nodes[qv].right);
        }
        if(que.size()>0){
        cout<<nodes[qv].data<<" ";
        }else{
            cout<<nodes[qv].data;
        }
    }
    
    
    
}  
//根据题目的意思建立一颗树然后对这颗树调用广度优先算法打印出层序
// 题目已经
直接写出来了那就不用java写一遍了





1100 Mars Numbers
People on Mars count their numbers with base 13:
Zero on Earth is called "tret" on Mars.
The numbers 1 to 12 on Earth is called "jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec" on Mars, respectively.
For the next higher digit, Mars people name the 12 numbers as "tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou", respectively.
For examples, the number 29 on Earth is called "hel mar" on Mars; and "elo nov" on Mars corresponds to 115 on Earth. In order to help communication between people from these two planets, you are supposed to write a program for mutual translation between Earth and Mars number systems.
   1. people on mars  count their numbers with base 13:
   2. zero  on Earth is called "tret" on Mars.
   3. The numbers 1 to 12 is called 
     大概是关于13 进制,督导这里就
 

首先将人类语言转换成火星文
思路是什么?
 人类转成火星文好想好简单一点
 string ret = "";
 while(x){
    ret+=chars[x%13];
    x/=13;
 }在这个过程上加一些东西,或者减掉一些东西
 将字符串取反就行了
 
火星文转换成人类语言
也是一样从最基础的来写
int res = 0;
string temp = "xxx";//对应的火星文
for(int i = 0;i<temp.length();i++){
    res = map.get(temp[i]) + res*13;
}
return res;


大概是这么一个过程如果有错最多加一点点修改就可以了

思路已经有了  自己能写出来就是完全掌握,
不过有些东西已经写过好几遍了, 输出一些也可以了

首先你需要判断给定的是火星字还是地球数字
string str;
getline(cin,str);



```java
#include<iostream>
#incldue<unordered_map>
using namespace std;
string chartoint[] = {"tret","jan", "feb", "mar", "apr", "may","jun", "jly", "aug", "sep", "oct", "nov"}; "dec" };
string chartoint2[] = {"tret","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
map<string,int> map1;
unordered_map <string,int> map;
int main(){
    int n;
    cin>>n;
    for(int i = 0;i<13;i++){
        map1[chartoint[i]] = i;
        map2[chartoint2[i]] = i;
    }
    
    for(int i = 0;i<n;i++){
        string str;
        getline(cin,str);
        if(str[0] >= '0' && str[0] <= '9'){
            string ret;
            int x = 0;
            for(int i  =0;i<str.length;i++){
                x = str[i]-'0'+x*10;
            }
            int first = 0;
            while(x>0){
                if(first == 0){
                    first = 1;
                   ret+== chartoint[x%13];
                    x/=13;
                }else{
                    ret++chartoint2[x%13];
                    x/=13;
                }
            }
            for(int i = 0;i<ret.length();i++){
                if(i!=0){
                    cout<< ret[i];
                }else{
                    cout<<ret[i]<<" ";
                }
            }

        }else{
            int ret = 0;
            string temp = "";
            for(int i  =0;i<str.length();i++){
                if(str[i] != " "){
                    temp+=str[i];
                }else{
                    ret = map[temp]+ret*13;
                }
            }
            cout<<ret;
        }
    }
}




#include<iostream>
#include<map>
using namespace std;
string chartoint[] = {"tret","jan", "feb", "mar", "apr", "may","jun", "jly", "aug", "sep", "oct","nov", "dec" };
string chartoint2[] = {"tret","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
set<string> set1;
map<string,int> map1;
int main(){
    int n;
    cin>>n;
    for(int i = 0;i<13;i++){
        map1[chartoint[i]] = i;
        map1[chartoint2[i]] = i;
        set1.insert(chartoint2[i]);
    }
    string temp;
    getline(cin,temp);
    for(int i = 0;i<n;i++){
        string str;
        getline(cin,str);
        if(str[0] >= '0' && str[0] <= '9'){
            vector<string> ret;
            int x = 0;
            for(int j  =0;j<str.length();j++){
                x = (str[j]-'0')+x*10;
            }
            
            int first = 0;
            while(x>0){
                if(first == 0){
                    first = 1;
                    if(x%13 !=0){
                   ret.push_back(chartoint[x%13]);
                    }
                        x/=13;
                }else{
                  ret.push_back(chartoint2[x%13]);
                    x/=13;
                }
            }
            for(int j = ret.size()-1;j>=0;j--){
                if(j!=0){
                    cout<<ret[j]<<" ";
                }else{
                    cout<<ret[j];
                }
            }
             cout<<endl;
        }else{
            int ret = 0;
            string temp = "";
            for(int j  =0;j<str.length();j++){
                if(str[j] != ' '){
                    temp+=str[j];    
                }else{
                    ret = map1[temp]+ret*13;
                    temp = "";
                }
            }
            if(set1.find(temp) != set1.end()){
                ret = map1[temp]*13;
            }else{
            ret = map1[temp]+ret*13;
            }
            cout<<ret<<endl;
        }
    }
}




``

   
还是有点细节的
我觉的有25分
可以  通过输出强行让我写了两题
加了一点瘦脸度
不行了  已经12点多了
我要睡觉了
但是很想打吧游戏


打吧游戏就睡了
我只能自律不能自虐




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值