猿辅导2019校园招聘研发岗位在线笔试编程题-2018.08.26
程序员文章站
2023-12-24 22:09:09
...
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int memberCount, carCount;
cin >> memberCount >> carCount;
int* members = new int[memberCount];
for(int i=0; i<memberCount; i++){
cin >> members[i];
}
vector<int> res;
int remainder = memberCount%carCount;//余数
int business = memberCount/carCount;//商 出去余数外剩余区间个数
if(remainder){//最后面的区间加入数组
for(int i=0; i<remainder; i++)
res.push_back(members[business*carCount+i]);
}
memberCount -= remainder;
for(int i=business-1; i>=0; i--){//区间从后往前依次加入数组
for(int j=0; j<carCount; j++){
res.push_back(members[carCount*i+j]);
}
}
if(!res.size())
return 0;
for(int i=0; i<res.size()-1; i++)
cout << res[i] << " ";
cout << res[res.size()-1] << endl;
delete[] members;
return 0;
}
/*
5 3
1 3 5 2 4
9 3
1 2 3 4 5 6 7 8 9
2 3
1 2
*/
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int N;
int main()
{
scanf("%d\n", &N);
int k = N/3;
string str;
getline(cin, str);
int temp = 2*k-1;//上半部分两个字符间的空格个数
//输出Y的上半部分
for(int i=0; i<k; i++){
for(int j=0; j<i; j++)//输出前面空格
printf(" ");
printf("%c", str[2*i]);
for(int q=0; q<temp; q++){//输出中间空格
printf(" ");
}
temp -= 2;
printf("%c\n", str[2*i+1]);
}
//输出Y的下半部分
for(int i=0; i<=k; i++){
for(int j=0; j<k; j++)
printf(" ");
printf("%c\n", str[2*k+i]);
}
return 0;
}
/*
4
a3f/
7
abcdefg
10
iiiiiiiiii
*/