UVa120 Stacks of Flapjacks

#include <iostream>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
using namespace std;

const int MAXN = 30;
vector<int> v;

void reverse(int a[], int top, int bottom) {
	for (int i = top; i <= (top + bottom)/2; i++) {
		int temp = a[i];
		a[i] = a[top + bottom - i];
		a[top + bottom - i] = temp;
	}
}

void flip_sort(int a[], int dpt) {
	v.clear();
	for (int i = 0; i < dpt; i++) {
		int max = a[0];
		int index = 0;
		for (int j = 0; j < dpt - i; j++) {
			if (a[j] > max) {
				max = a[j];
				index = j;
			}
		}
		if (index == dpt - i - 1) continue;
		else {
			if (index != 0) {
				reverse(a, 0, index);
				v.push_back(dpt - index);
			}
			reverse(a, 0, dpt - i - 1);
			v.push_back(i + 1);
		}
	}
	v.push_back(0);
}

int main() {
	int a[MAXN], b[MAXN];
	string str;
	while (getline(cin, str)) {
		int cnt = 0;
		stringstream ss;
		ss << str;
		memset(a, 0, sizeof(a));
		while (ss >> a[cnt])
			cnt++;
		for (int i = 0; i < cnt; i++)
			b[i] = a[i];
		flip_sort(a, cnt);
		cout << b[0];
		for (int i = 1; i < cnt; i++)
			cout << ' ' << b[i];
		cout << endl;
		cout << *v.begin();
		for (auto i = ++v.begin(); i != v.end(); i++)
			cout << ' ' << *i;
		cout << endl;
	}
	return 0;
}
1.下标的问题还是要注意
2.连续的数字输入目前除了string stream没发现什么好办法
3.debug要做在提交前
4.读英文题目的能力还要加强
5.辣鸡udebug样例(滑稽

PS:写题这个东西还是要坚持,课业再重也要一点点进步。熟能生巧,投入了会有收获的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值