zoukankan      html  css  js  c++  java
  • L1-054 福到了->团体程序设计天梯赛-练习集

    题目

    “福”字倒着贴,寓意“福到”。不论到底算不算民俗,本题且请你编写程序,把各种汉字倒过来输出。这里要处理的每个汉字是由一个 N × N 的网格组成的,网格中的元素或者为字符 @ 或者为空格。而倒过来的汉字所用的字符由裁判指定。

    输入格式:

    输入在第一行中给出倒过来的汉字所用的字符、以及网格的规模 N (不超过100的正整数),其间以 1 个空格分隔;随后 N 行,每行给出 N 个字符,或者为 @ 或者为空格。

    输出格式:

    输出倒置的网格,如样例所示。但是,如果这个字正过来倒过去是一样的,就先输出bu yong dao le,然后再用输入指定的字符将其输出。

    输入样例 1:
    $ 9
     @  @@@@@
    @@@  @@@ 
     @   @ @ 
    @@@  @@@ 
    @@@ @@@@@
    @@@ @ @ @
    @@@ @@@@@
     @  @ @ @
     @  @@@@@
    
    输出样例 1:
    $$$$$  $ 
    $ $ $  $ 
    $$$$$ $$$
    $ $ $ $$$
    $$$$$ $$$
     $$$  $$$
     $ $   $ 
     $$$  $$$
    $$$$$  $ 
    
    输入样例 2:
    & 3
    @@@
     @ 
    @@@
    
    输出样例 2:
    bu yong dao le
    &&&
     & 
    &&&
    

    #include <stack>
    #include <string>
    #include <iostream>
    #include <vector>
    #include <algorithm>
    
    using namespace std;
    
    int main() {
    	stack<string> st;
    	vector<string> vec;
    
    	char ch;
    	int n;
    
    	// 数据输入部分
    	cin >> ch >> n;
    	cin.get();
    	while (n--) {
    		string str;
    		getline(cin,str);
    		st.push(str);
    	}
    
    	// 数据处理部分
    	bool bIsSame = true;
    	while (!st.empty()) {
    		string temp = st.top();
    		reverse(temp.begin(),temp.end());
    		if (temp != st.top()) {
    			bIsSame = false;
    		}
    		for (auto it = temp.begin(); it != temp.end(); it++) {
    			*it = *it != ' ' ? ch : *it;
    		}
    		vec.push_back(temp);
    		st.pop();
    	}
    
    	// 数据输出部分
    	if (bIsSame == true) {
    		cout << "bu yong dao le" << endl;
    	}
    	for (auto it = vec.begin(); it != vec.end(); it++) {
    		cout << *it << endl;
    	}
    
    	return 0;
    }
    
    
  • 相关阅读:
    Linux的sz和rz命令
    python正则表达式(8)--分组、后向引用、前(后)向断言
    python正则表达式(7)--flag修饰符、match对象属性
    python正则表达式(6)--split、sub、escape方法
    python正则表达式(5)--findall、finditer方法
    python正则表达式(4)--search方法
    python正则表达式(3)--match方法
    python正则表达式(2)--编译正则表达式re.compile
    Go语言开发教程
    zabbix源码编译安装以及添加第一台host监控
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12537712.html
Copyright © 2011-2022 走看看