第一次找实习面试

从成都的小公司投起试手

锐狐

很羞耻的是连笔试都没过,应该也不算是很难的编程题,大概是Java课后编程习题的水平,属实惭愧
事后复盘

打印三角形

*
**
***
****
*****
****
***
**
*

public static void printDiamond(){
System.out.println("Enter zhe side length of the diamond:");
Scanner scanner = new Scanner(System.in);
int n=scanner.nextInt();
// 分为上下层打印
for(int i = 0;i<n;++i){
for (int j=0;j<i;++j){
System.out.print("*");
}
System.out.println();
}
for(int i=n;i>0;--i){
for (int j=0;j<i;++j){
System.out.print("*");
}
System.out.println();
}
}

但是说不能直接打印的嘛,这样算不算是直接打印

打印菱形

怎么从键盘获取一个数组串

C++

力扣做多了,就太习惯拿着参数就用了,基本没想过怎么从键盘获取
输入一串数字,然后把它封装成一个数组

我想到了《剑指Offer》-67-字符串转整数,以及46-数字翻译成字符串

定义输入以空格分隔的一行整数,例如4 5 45 -3 6 28 15 7
定义输出int数组

string str, temp;
getline(cin, str);
vector<int> vec;
for (int i = 0; i < str.size(); ++i) {
if (str[i] != ' ') {
temp += str[i];
// 存入最后一个数字
if (i == str.size() - 1) {
vec.push_back(atoi(temp.c_str()));
}
}
else {
vec.push_back(atoi(temp.c_str()));
temp.clear();
}
}
/*for (vector<int>::iterator it = vec.begin(); it < vec.end(); ++it) {
cout << *it << " ";
}*/
int len = vec.size();
int* buffer = new int[len];
if (!vec.empty()) {
memcpy(buffer, &vec[0], len * sizeof(int));
}

我有尝试去把这段代码封装成一个方法,但看起来有点麻烦而且没有多大意义

Java按字节截取字符

本文作者:YaosGHC

本文链接:https://www.cnblogs.com/yaocy/p/16354093.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   YaosGHC  阅读(42)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起