题目链接:http://poj.org/problem?id=2013

设长度非递减的字串序列为s[1]...s[n]。设计递归子程序print(n),其中n为字串序号,每分析1个字串,n=n-1。 n = 0 为边界。字串s为局部变量:

  先输入和输出当前组的第1个字串s,n = n - 1;

若n > 0,则输入当前组的第2个字符s,n = n - 1。若n > 0,则通过递归调用print(n)将字串s入栈。回溯过程相当于栈顶字串s出栈,因此直接输出s。

 #include <iostream>
#include <string>
using namespace std; void print(int n) // 输入n个字串,并按对称格式输出
{
string s; // 当前字串
cin >> s; // 输入和输出当前组的第1个字串
cout << s << endl;
if (--n)
{
cin >> s; // 输入当前组的第2个字串并通过递归压入系统栈区
if (--n)
{
print(n);
}
cout << s << endl; // 回溯,栈首字串出栈后输出
}
} int main()
{
int n, loop = ; // 字串集合序号初始化
while (cin >> n && n)
{
printf("SET %d\n", ++loop);
print(n); // 按照对称格式输出当前字串集合中的n个字串
}
return ;
}

不用递归也可以。对称的输出形式由两部分组成:

  上半部分由自上而下的奇数行组成:

s[1]

s[3]

s[5]

......

n 为奇数时为s[n],n为偶数时为s[n-1]

即执行语句 "for (int i = 1; i <= n; i += 2)    cout << s[i] << endl; "

下半部分由自下而上的偶数行组成:

s[n - (n%2)]

s[n - (n%2) - 2]

  s[n -  (n%2) - 4]

......

  s[2]

即执行语句" for (int  i = n - (n%2); i > 1; i -= 2)  cout << s[i] << endl; "。

poj 2013 Symmetric Order 解题报告的更多相关文章

  1. OpenJudge/Poj 2013 Symmetric Order

    1.链接地址: http://bailian.openjudge.cn/practice/2013 http://poj.org/problem?id=2013 2.题目: Symmetric Ord ...

  2. Tarjan算法求解桥和边双连通分量(附POJ 3352 Road Construction解题报告)

     http://blog.csdn.net/geniusluzh/article/details/6619575 在说Tarjan算法解决桥和边双连通分量问题之前我们先来回顾一下Tarjan算法是如何 ...

  3. POJ 3126 Prime Path 解题报告(BFS & 双向BFS)

    题目大意:给定一个4位素数,一个目标4位素数.每次变换一位,保证变换后依然是素数,求变换到目标素数的最小步数. 解题报告:直接用最短路. 枚举1000-10000所有素数,如果素数A交换一位可以得到素 ...

  4. [POJ 1002] 487-3279 C++解题报告

        487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 228365   Accepted: 39826 D ...

  5. 【原创】poj ----- 2376 Cleaning Shifts 解题报告

    题目地址: http://poj.org/problem?id=2376 题目内容: Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K ...

  6. 【原创】poj ----- 1611 The Suspects 解题报告

    题目地址: http://poj.org/problem?id=1611 题目内容: The Suspects Time Limit: 1000MS   Memory Limit: 20000K To ...

  7. 【原创】poj ----- 2524 Ubiquitous Religions 解题报告

    题目地址: http://poj.org/problem?id=2524 题目内容: Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 6 ...

  8. 【原创】poj ----- 3009 curling 2 解题报告

    题目地址: http://poj.org/problem?id=3009 题目内容: Curling 2.0 Time Limit: 1000MS   Memory Limit: 65536K Tot ...

  9. [POJ 1001] Exponentiation C++解题报告 JAVA解题报告

        Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 126980   Accepted: 30 ...

随机推荐

  1. 【BZOJ-1030】文本生成器 AC自动机 + DP

    1030: [JSOI2007]文本生成器 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 3253  Solved: 1330[Submit][Stat ...

  2. BZOJ-1228 E&D 博弈SG+找啊找啊找规律

    讨厌博弈,找规律找半天还是错的.... 1228: [SDOI2009]E&D Time Limit: 10 Sec Memory Limit: 162 MB Submit: 666 Solv ...

  3. 【bzoj1202】 HNOI2005—狡猾的商人

    http://www.lydsy.com/JudgeOnline/problem.php?id=1202 (题目链接) 题意 给出m段区间和,判断是否存在某段区间与之前读入的区间相矛盾. Soluti ...

  4. POJ2186 Popular Cows

    Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= ...

  5. [NOIP2010] 提高组 洛谷P1525 关押罪犯

    刚才做并查集想到了这道以前做的题,干脆一并放上来 题目描述 S 城现有两座监狱,一共关押着N 名罪犯,编号分别为1~N.他们之间的关系自然也极不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可 ...

  6. POJ3233Matrix Power Series(十大矩阵问题之三 + 二分+矩阵快速幂)

    http://poj.org/problem?id=3233 Matrix Power Series Time Limit: 3000MS   Memory Limit: 131072K Total ...

  7. php返回json数据简单实例

    <?php include './include/conn.php'; //数据库链接文件 $sql_notice = mysql_query('SELECT * FROM gg_notice ...

  8. KxMenu下拉菜单

    + (void)createMenu:(id)sender target:(UIViewController *)t { NSArray *menuItems = @[ [KxMenuItem men ...

  9. 如何获取xcassets中LaunchImage图片

    NSDictionary * dic = @{@"320x480" : @"LaunchImage-700", @"320x568" : @ ...

  10. ios 随机色 宏定义

    #define RGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1] #d ...