日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Codeforces Beta Round #5 B. Center Alignment 模拟题

發布時間:2023/12/19 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Beta Round #5 B. Center Alignment 模拟题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

B. Center Alignment

題目連接:

http://www.codeforces.com/contest/5/problem/B

Description

Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor ?Textpad? decided to introduce this functionality into the fourth release of the product.

You are to implement the alignment in the shortest possible time. Good luck!

Input

The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.

Output

Format the given text, aligning it center. Frame the whole text with characters ?*? of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.

Sample Input

This is

Codeforces
Beta
Round
5

Sample Output


  • This is *
  • * Codeforces
  • Beta *
  • Round *
  • 5 *

Hint

題意

給你一堆字符串,讓你居中

如果恰好居中的話,那就居中

如果不是的話,先偏左邊,然后再偏右邊去

題解:

模擬題,按照題意模擬就好了。

代碼

#include<bits/stdc++.h> using namespace std; const int maxn = 2005; string s[maxn],s1; int mx,tot; int main() {while(getline(cin,s1)){s[tot++]=s1;mx = max((int)s1.size(),mx);}for(int i=0;i<mx+2;i++)cout<<"*";cout<<endl;int d = 0;for(int i=0;i<tot;i++){cout<<"*";int len = (mx-s[i].size());if(len%2==1)d++;int l = len/2;int r = len/2;if(len%2==1&&d%2==1)r++;else if(len%2==1)l++;for(int j=0;j<l;j++)cout<<" ";cout<<s[i];for(int j=0;j<r;j++)cout<<" ";cout<<"*"<<endl;}for(int i=0;i<mx+2;i++)cout<<"*";cout<<endl; }

轉載于:https://www.cnblogs.com/qscqesze/p/5304189.html

總結

以上是生活随笔為你收集整理的Codeforces Beta Round #5 B. Center Alignment 模拟题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。