Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

请问这题怎么debug (附代码)

Posted by kakassi at 2009-08-09 22:06:41 on Problem 1214
数据量如此之大 没有解题报告 没有正确代码 。。。。。
错了我也不知道怎么改:

唉 先把我的代码放这边来
#include <vector>
#include <string>
#include <iostream>
using namespace std;

class card {
public:
	char suit;//D H S C
	char rank;// A 2 3 4 5 6 7 8 9 T J Q K
//	char llsuit;  犹豫移牌之后 这四个域的修改太多 所以先删去
//	char llrank;
//	char lsuit;  
//	char lrank; 
	int matchll;
	int matchl;
	int total;
};

void update(vector<card> & cards,int i){
		if(i>0){
			if(cards[i].rank==cards[i-1].rank || cards[i].suit == cards[i-1].suit)
				cards[i].matchl = 1;
			else
				cards[i].matchl = 0;
		}
		else{
			cards[i].matchl = 0;
		}
		if(i>2){
			if(cards[i].rank==cards[i-3].rank || cards[i].suit == cards[i-3].suit)
				cards[i].matchll = 1;	
			else 
				cards[i].matchll = 0;
		}
		else{
			cards[i].matchll = 0;
		}

}
void updatel(vector<card> & cards,int i){
		if(i>0){
			if(cards[i].rank==cards[i-1].rank || cards[i].suit == cards[i-1].suit)
				cards[i].matchl = 1;
			else
				cards[i].matchl = 0;
		}
		else{
			cards[i].matchl = 0;
		}
}
void updatell(vector<card> & cards,int i){
		if(i>2){
			if(cards[i].rank==cards[i-3].rank || cards[i].suit == cards[i-3].suit)
				cards[i].matchll = 1;	
			else 
				cards[i].matchll = 0;
		}
		else{
			cards[i].matchll = 0;
		}

}

int main(int argc, char* argv[])
{
	int i;
	vector <card> cards(52);
	string str;
	while(1){
      for(i=0;i<52;i++){
		cin >> str;
		if(str=="#")
			return 0;
		cards[i].rank = str[0];
		cards[i].suit = str[1];
		cards[i].total = 1;
		if(i>0){
			if(cards[i].rank==cards[i-1].rank || cards[i].suit == cards[i-1].suit)
				cards[i].matchl = 1;
			else
				cards[i].matchl = 0;
		}
		else{
			cards[i].matchl = 0;
		}
		if(i>2){
			if(cards[i].rank==cards[i-3].rank || cards[i].suit == cards[i-3].suit)
				cards[i].matchll = 1;	
			else 
				cards[i].matchll = 0;
		}
		else{
			cards[i].matchll = 0;
		}
	  }
//	cout << cards[0].lsuit << " " <<cards[0].lrank<< " "<< cards[0].matchl<< endl;
	  i = 0;
	  while(i<cards.size()){
		if(cards[i].matchll==1){
			cards[i-3].suit = cards[i].suit;
			cards[i-3].rank = cards[i].rank;
			cards[i-3].total = cards[i-3].total + cards[i].total;
			//重新计算i-3的matchl和matchll
			update(cards,i-3);
			cards.erase(&cards[i]);
			updatel(cards,i-2);
			update(cards,i);
			updatell(cards,i+1);
			updatell(cards,i+2);
			i=i-3;
			continue;
		}
		if(cards[i].matchl==1){
			cards[i-1].suit = cards[i].suit;
			cards[i-1].rank = cards[i].rank;
			cards[i-1].total = cards[i-1].total+cards[i].total;
			update(cards,i-1);
			cards.erase(&cards[i]);
			updatell(cards,i);
			updatell(cards,i+1);
			i = i -1;
			i=0;
			continue;
		}
		i++;
/* for debug  用来显示每张牌  sigh
		int j;
		for(j=0;j<cards.size();j++)
			cout << cards[j].rank << cards[j].suit << cards[j].total << "  ";
		cout <<endl<< "***************************************** "<<endl << endl;
*/
	  }
	  cout << cards.size() <<" piles remaining:" ;
	  for (i=0;i<cards.size();i++){
		cout << " " <<cards[i].total;
	  }
	  cout << endl;
	}	
	system("PAUSE");
	return 0;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator