| ||||||||||
| 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 | |||||||||
大家帮忙看看啊,1002问题算法先不考虑,我就想提交成功一个。源代码如下,本地测试通过,但是提供却WA。晕~
#include <iostream>
#include <stdlib.h>
#include <string>
#include <fstream>
using namespace std;
string cvt(string);
void out(string s,int n);
//start
struct Node{
string numStr;
int cnt;
Node * next;
};
Node * create(void){
string nowStr;
long i;
int n;
Node * p, * q, *r, * head;
cin>>n;//read lines.
head=new Node;
head->next=NULL;
for(i=0;i<n;i++){
cin>>nowStr;
nowStr=cvt(nowStr);
p=new Node;
p->next=NULL;
p->cnt=1;
p->numStr=nowStr;
r=head;
q=r->next;
if(q==NULL){ //empty list
r->next=p;
p->cnt=1;
}else{ //not empty
while((q!=NULL)&&(q->numStr<p->numStr)){
r=q;
q=q->next;
}
if(q==NULL){ //insert to tail
p->cnt=1;
p->next=NULL;
r->next=p;
}else if(q->numStr==p->numStr) //increase cnt
q->cnt++;
else{ //insert into mid
p->cnt=1;
p->next=q;
r->next=p;
}
}
}
return head;
}
string cvt(string srce){
//convert anything into the from of xxxxxxx(7 numbers)
int i,j,n;
i=0;j=0;n=0;
string res("0000000");
res[0]=srce[0];
n=srce.length();
for(i=0;i<n;i++){
switch(srce[i]){
case 'A': case 'B': case 'C': res[j++]='2';break;
case 'D': case 'E': case 'F': res[j++]='3';break;
case 'G': case 'H': case 'I': res[j++]='4';break;
case 'J': case 'K': case 'L': res[j++]='5';break;
case 'M': case 'N': case 'O': res[j++]='6';break;
case 'P': case 'R': case 'S': res[j++]='7';break;
case 'T': case 'U': case 'V': res[j++]='8';break;
case 'W': case 'X': case 'Y': res[j++]='9';break;
case '-': case ' ':break;
default: res[j++]=srce[i];
}
}
return res;
}
void out(string s,int n){
int i;
for(i=0;i<3;i++) cout<<s[i];
cout<<'-';
for(i=3;i<8;i++) cout<<s[i];
cout<<n<<endl;
}
void prtlist(Node * head){
Node * p;
p=head->next;
while((p!=NULL)&&(p->cnt<=1)){
p=p->next;
}
if(p!=NULL){
while(p!=NULL){
if(p->cnt>1) out(p->numStr,p->cnt);
p=p->next;
}
}else{
cout<<"No duplicates.\n";
}
/* while(p!=NULL){
out(p->numStr,p->cnt);
p=p->next;
}
*/
}
int main()
{
Node * head;
head=create();
prtlist(head);
return 0;
}
是不是格式上有什么问题还是怎么的?要是TE也就算了,问题是WA啊。
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator