牛客网-好未来秋招

    xiaoxiao2021-04-13  35

    编程题一

    将一句话的单词进行倒置,标点不倒置。比如 I like beijing. 经过函数后变为:beijing. like I

    import java.util.Scanner; public class Main { public static void main(String args[]){ Scanner scanner = new Scanner(System.in); String a = scanner.nextLine(); String m[] = a.split(" "); for(int i =m.length-1;i>=0;i--){ if(i==0) System.out.print(m[i]); else System.out.print(m[i]+" "); } } }

    编程题二

    输入两个字符串,从第一字符串中删除第二个字符串中所有的字符。例如,输入”They are students.”和”aeiou”,则删除之后的第一个字符串变成”Thy r stdnts.” 有点投机取巧 尴尬

    include <iostream> #include <stdio.h> #include <cstring> using namespace std; int main(){ char a[500]; char b[500]; cin.get(a,500); cin.ignore(); cin.get(b,500); int m = strlen(a); int n = strlen(b); for(int i =0;i < m;i++){ for(int j =0;j<n;j++){ if(a[i] == b[j]) a[i]='*'; } } for(int q = 0;q<m;q++){ if(a[q]!='*') cout<<a[q]; } return 0; }

    编程题三

    输入两个整数 n 和 m,从数列1,2,3…….n 中随意取几个数,使其和等于 m ,要求将其中所有的可能组合列出来; 输入5 5 输出 1 4 2 3 5 这道题可以采用递归加回溯的方法解决,也不难。

    #include <iostream> #include <vector> using namespace std; void find(vector<vector<int>> &res, vector<int> &t, int now, int sum, int n, int m); int main(){ int n, m; cin >> n; cin >> m; vector<vector<int>> res; vector<int>t; find(res, t, 0, 0, n, m); for (int i = 0; i < res.size(); i++){ for (int j = 0; j < res[i].size(); j++){ if (j == res[i].size() - 1) cout << res[i][j]; else cout << res[i][j] << " "; } if (i != res.size() - 1){ cout << endl; } } return 0; } void find(vector<vector<int>> &res, vector<int> &t, int now, int sum, int n,int m){ if (sum == m){ res.push_back(t); return; } if (sum > m) return; now++; if (now > n) return; t.push_back(now); find(res, t, now,sum+now, n, m); t.pop_back(); find(res, t, now, sum, n, m); }

    后记

    也是因为最近收到好未来教育的实习生笔试通知,所以也要做个题目练习一下防止到时候一道题都做不出来很尴尬。 毕竟,这家公司不算是真正的互联网企业,因此笔试的题目也不是太难,仔细想一下还是可以琢磨出来的。

    转载请注明原文地址: https://ju.6miu.com/read-669502.html

    最新回复(0)