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

1885 why can't i pass.........puzzling.

Posted by fjctlzy at 2006-03-16 18:13:59
#include<iostream>
#include<string>
using namespace std;
int change(int k,int j);
bool isalpha(char ch);
int pow(int base,int x);
void check(int num,int pos1,int pos2);
string a;
int lenOfTemp;
int lenOfNum;
int main(){
	getline(cin,a,'0');
   
    int num;
	int i,j,k;
	for (i=0;i<a.length();i++){
		if (isdigit(a[i])){
			  j=i;
			  k=i;
			  while (isdigit(a[j])){
				  j++;
			  }
			  num=change(k,j); 
			  check(num,i,j-1);
			  i=i+lenOfTemp-1;
		} 
	}
    cout<<a;
	return 0;
}

bool isalpha(char ch){
	if ((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
		return true;
	else return false;
}

int pow(int base,int x){
	int temp=1;
	for (int i=0;i<x;i++)
		temp=temp*10;
   return temp;
}
int change(int k,int j){

    int b[10];
	int i=j-k-1;
	int temp=k;
	while(temp<j){
       b[i]=a[temp]-'0';
	   temp++;
	   i--;   
	}
    int total=0;
      for (i=0;i<j-k;i++)
	   total+=b[i]*pow(10,i);
	
return total;
}

void check(int num,int pos1,int pos2){
	string b[10000];
	int count=-1;
	int j=pos1;
	int k;
	string temp;
	bool ok;
		while(num>0){
			ok=true;
	      while(!isalpha(a[j]))//not alpha
	        j--; 
		   
		  k=j;
	      while(isalpha(a[k]))
		    k--;
		  temp=a.substr(k+1,j-k);
		  for (int m=0;m<=count;m++){
			  if (temp==b[m]){
				  ok=false;
				  break;
			  }
		  }
			  if (ok){
				  num--;
	              count++;
				  b[count]=temp;
		          j=k;
			  }
			  else j=k;
		}
		string c=a.substr(0,pos1)+temp+a.substr(pos2+1,a.length()-pos2-1 );
		a=c;
		lenOfTemp=temp.length();
}
        

	

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