110407 ShellSort
来源:互联网 发布:手机浏览器看源码 编辑:程序博客网 时间:2024/05/22 17:26
This solution gets "Wrong answer" result inhttp://www.programming-challenges.com/,
but it gets "Accepted" result inhttp://uva.onlinejudge.org/.
According to the explanation in http://www.programming-challenges.com/problems_specific.txt, I think my program should be correct, and it is the problem of http://www.programming-challenges.com/to judge my program as "Wrong answer".
#include <iostream>#include <map>#include <string>using namespace std;struct Tortoise{string m_name;int m_index;};typedef Tortoise* TortoisePtr;static void ShellSort(TortoisePtr* tortoises, int cnt){if (cnt <= 1)return;int toHandleMaxTortoiseIndex = 0;while(tortoises[toHandleMaxTortoiseIndex]->m_index != (cnt - 1))++toHandleMaxTortoiseIndex;int searchSecondMaxFrom = (toHandleMaxTortoiseIndex == 0) ? 1 : 0;for (int k = cnt; k >= 2; --k){int j = searchSecondMaxFrom;while(tortoises[j]->m_index != (k - 2))++j;if (toHandleMaxTortoiseIndex < j){cout << tortoises[j]->m_name << endl;TortoisePtr temp = tortoises[j];for (int x = j; x >= 1; --x)tortoises[x] = tortoises[x - 1];tortoises[0] = temp;toHandleMaxTortoiseIndex = 0;++searchSecondMaxFrom;}elsetoHandleMaxTortoiseIndex = j;}}static void RunTestCase(){int cnt;cin >> cnt;cin.ignore(); // Consume the '\n' after the count of tortoises.TortoisePtr* tortoises = new TortoisePtr[cnt];for (int i = 0; i < cnt; ++i){tortoises[i] = new Tortoise();getline(cin, tortoises[i]->m_name);}map<string, int> queueInfo;string temp;for (int i = 0; i < cnt; ++i){getline(cin, temp);queueInfo.insert(pair<string, int>(temp, i));}for (int i = 0; i < cnt; ++i)tortoises[i]->m_index = queueInfo[tortoises[i]->m_name];ShellSort(tortoises, cnt);for (int i = 0; i < cnt; ++i)delete tortoises[i];delete[] tortoises;}static void Test(){int cnt;cin >> cnt;for (int i = 0; i < cnt; ++i){RunTestCase();cout << endl;}}int main(int argc, char* argv[]){Test();return 0;}
- 110407 ShellSort
- ShellSort
- ShellSort
- shellsort
- shellSort
- shellsort
- ShellSort
- ShellSort
- 【shellSort】
- ShellSort
- ShellSort
- shellsort
- shellsort
- programming-challenges ShellSort (110407) 题解
- Java ShellSort
- uva10152 ShellSort
- 10152 - ShellSort
- 10152 - ShellSort
- Jquery tab效果,可以指定显示默认项目
- 黄帝的祖先是谁
- 淘宝关键词推荐技术介绍
- C语言中free()出错
- 在Linux下开启背光Led键盘的背光
- 110407 ShellSort
- Linux下的常用软件集锦
- 不用库函数反转字符串
- 一淘商品类目预测
- gdi在图画上写字
- sprintf
- 转载Socket详解
- 黑马程序员_编程学习心得
- 淘宝大型数据仓库的治理(1)- 数据需求响应慢 实时相应需求