zoukankan      html  css  js  c++  java
  • PAT 1036. 跟奥巴马一起编程

    美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统。2014年底,为庆祝“计算机科学教育周”正式启动,奥巴马编写了很简单的计算机代码:在屏幕上画一个正方形。现在你也跟他一起画吧!

    输入格式:

    输入在一行中给出正方形边长N(3<=N<=20)和组成正方形边的某种字符C,间隔一个空格。

    输出格式:

    输出由给定字符C画出的正方形。但是注意到行间距比列间距大,所以为了让结果看上去更像正方形,我们输出的行数实际上是列数的50%(四舍五入取整)。

    输入样例:

    10 a
    

    输出样例:

    aaaaaaaaaa
    a        a
    a        a
    a        a
    aaaaaaaaaa
    

    分析

    这道题是简单的,没什么说的→_→

    代码如下

    #include<iostream>
    #include<math.h>
    using namespace std;
    int main(){
    	int row,colunm;
    	char c;
    	cin>>colunm>>c;
    	row=round(colunm*0.5);
    	string r(colunm,c),s(colunm-2,' ');
    	cout<<r<<endl;
    	for(int i=0;i<row-2;i++)
    	cout<<c<<s<<c<<endl;
    	cout<<r<<endl;
    	return 0;
    }
    
  • 相关阅读:
    Valid Parentheses
    Remove Nth Node From End of List
    守护线程、守护进程
    4Sum
    Letter Combinations of a Phone Number
    3sum closest
    Excel Sheet Column Number
    Majority Element
    Balanced Binary Tree
    Maximum Depth of Binary Tree
  • 原文地址:https://www.cnblogs.com/A-Little-Nut/p/8116981.html
Copyright © 2011-2022 走看看