| ||||||||||
| 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>
#include <stdlib.h>
#include <string>
#include <fstream>
using namespace std;
ifstream cin("t.in");
ofstream cout("t.out");
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 repeat num.
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;
}
编译时错误:
686147\Main.cpp(25) : error C2872: 'cin' : ambiguous symbol
686147\Main.cpp(29) : error C2872: 'cin' : ambiguous symbol
686147\Main.cpp(91) : error C2872: 'cout' : ambiguous symbol
686147\Main.cpp(92) : error C2872: 'cout' : ambiguous symbol
686147\Main.cpp(93) : error C2872: 'cout' : ambiguous symbol
686147\Main.cpp(94) : error C2872: 'cout' : ambiguous symbol
686147\Main.cpp(109) : error C2872: 'cout' : ambiguous symbol
问题是搞不清楚CIN和COUT到底哪儿出现了二义。
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator