| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
对链表的操作不是很熟悉 做这道题时用了动态链表 但是运行时错误 不知哪错了 请各位高手帮忙看下 谢谢啦 ^_^#include<iostream>
using namespace std;
typedef struct node{
int data;
struct node *next;
}node,*list;
int H (int a){
int s=1;
do{
a=a/10;
s*=10;
}while(a/10!=0);
return s;
}
void main (){
int data,i=0,t=0;
list L;
node *head,*p,*p0,*p1,*p2,*p3;
head=new node;
p0=head;
head->next=NULL;
do{
cin>>data;
p=new node;
p->data=data;
p0->next=p;
p0=p;
}while(data!=0);
p->next=NULL;
L=head;
p1=L->next;
while(p1->next->next!=NULL)
{
int N,T=0;
N=p1->data;
t=H(N);
do{
do{
T+=N%10;
N=(N-N%10)/10;
t=t/10;
}while(t!=0);
t=H(T);
}while(T>10);
cout<<T<<endl;
p1=p1->next;
}
while(L->next!=NULL){
p2=L->next;
p3=p2->next;
L->next=p3;
delete p2;
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator