拍照隊列

題目
公司:猿輔導
類型:字符串
難度:1級
題意:把輸入的字符串按照Y字輸出。
注意:字符串中可能含有空格,所以如果用string讀入時,需要讀入一行。

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int arr[10005];
int main(){
	int n;
	cin>>n;
	string str;
	getchar();
	getline(cin, str);
	int u = 0;
	int k = (n-1)/3;
	for(int i = 0; i < k; i++){
		for(int j = 0; j < 2*k+1; j++){
			if(i==j || i+j==2*k) cout<<str[u++];
			else cout<<" "; 
		}
		cout<<endl;
	}
	for(int i = 0; i <= k; i++){
		for(int j = 0; j <=k; j++){
			if(j==k) cout<<str[u++];
			else cout<<" ";
		}
		cout<<endl;
	}
} 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章