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

数据都过了 还是通不过><

Posted by ADmiaomiao at 2012-07-14 11:30:32
#include<iostream>
#include<string>
using namespace std;
struct AA
{
	 long int n1,n2,n3;
	AA * next;
	int fuhao;
};

AA* create(int n)
{
    AA* head,*p1,*p2;
	int i=1;
	head=p1=p2=new AA;
	p1->n1=p1->n2=p1->n3=0;
	p1->fuhao=false;
		
	while(i<n)
	{
       p1=new AA;
	   p2->next=p1;
	   p2=p1;
	   p1->n1=p1->n2=p1->n3=0;
	   p1->fuhao=false;
	   
		 i++;
	} 
	p2->next=NULL;
	return head;
};//创建链表

void translate(AA * p,string s)
{

	   if(s=="negative")      
				 p->fuhao=true; 
	         else if(s=="zero")
				 p->n3+=0;
			 else if(s=="one")
				 p->n3+=1;       
			 else if(s=="two")      
				 p->n3+=2;       
			 else if(s=="three")    
				 p->n3+=3;       
			 else if(s=="four")     
				 p->n3+=4;       
			 else if(s=="five")     
				 p->n3+=5;       
			 else if(s=="six")      
				 p->n3+=6;       
			 else if(s=="seven")    
				 p->n3+=7;       
			 else if(s=="eight")    
				 p->n3+=8;       
			 else if(s=="nine")     
				 p->n3+=9;       
			 else if(s=="ten")      
				 p->n3+=10;       
			 else if(s=="eleven")   
				 p->n3+=11;       
			 else if(s=="twelve")   
				 p->n3+=12;       
			 else if(s=="thirteen") 
				 p->n3+=13;       
			 else if(s=="fourteen") 
				 p->n3+=14;       
			 else if(s=="fifteen")  
				 p->n3+=15;       
			 else if(s=="sixteen")  
				 p->n3+=16;       
			 else if(s=="seventeen")
				 p->n3+=17;       
			 else if(s=="eighteen") 
				 p->n3+=18;       
			 else if(s=="nineteen") 
				 p->n3+=19;       
			 else if(s=="twenty")   
				 p->n3+=20;       
			 else if(s=="thirty")  
				 p->n3+=30;       
			 else if(s=="forty")   
				 p->n3+=40;       
			 else if(s=="fifty")  
				 p->n3+=50;       
			 else if(s=="sixty")   
				 p->n3+=60;       
			 else if(s=="seventy")  
				 p->n3+=70;       
			 else if(s=="eighty")
				 p->n3+=80;       
			 else if(s=="ninety")  
				 p->n3+=90;       
			 else if(s=="hundred") 
				 p->n3*=100;       
			 else if(s=="thousand")    
			 {        
				 p->n3*=1000;
			     p->n2=p->n3;        
			      p->n3=0;   
			 }       
			 else if(s=="million")        
			 {               
				 p->n3*=1000000;        
				 p->n1=p->n3;        
				 p->n3=0;       
			 }
}

int main()
{
	  AA *head;
	  AA *p;
     p=head=create(80);
	  string str;
	  int i=0,k=0;
	  for(;head->next!=NULL;head=head->next)
	  { 
		  
		  
	      while(cin.peek()!='\n')
		  {
			  cin>>str;
		  translate(head,str);		  
		  }
		  i++;
		  
		  if(getchar()=='\n'&&cin.peek()=='\n')
			  break;
	  }
	  for(k=0;k<i;k++,p=p->next)
	  {
		  if(p->fuhao==true)
			  cout<<"-";
		  cout<<(p->n1)+(p->n2)+(p->n3)<<endl;
	  }
	  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