| ||||||||||
| 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 | |||||||||
Re:各位大牛帮忙看下 程序为什么老是waIn Reply To:各位大牛帮忙看下 程序为什么老是wa Posted by:343051232 at 2008-11-10 21:14:33 > #include<iostream>
> #include<string.h>
> using namespace std;
> struct In
> {
> char str[100];
> }s[1000000];
> int res[1000000][2];
> int cmp(const void *a,const void *b)
> {
> return strcmp((*(In *)a).str,(*(In *)b).str);
> }
> void pan(char &a)//将字母转换成数字
> {
>
> if(a=='A'||a=='B'||a=='c')
> a='2';
> if(a=='D'||a=='E'||a=='F')
> a='3';
> if(a=='G'||a=='H'||a=='I')
> a='4';
> if(a=='J'||a=='K'||a=='L')
> a='5';
> if(a=='M'||a=='N'||a=='O')
> a='6';
> if(a=='P'||a=='R'||a=='S')
> a='7';
> if(a=='T'||a=='U'||a=='V')
> a='8';
> if(a=='W'||a=='X'||a=='Y')
> a='9';
> }
> void change(In *a,int n)//将字母转换成数字 以及去掉“-”
> {
> for(int i=0;i<n;i++)
> {
> for(unsigned int j=0;j<strlen(a[i].str);j++)
> {
> pan(a[i].str[j]);
> if(a[i].str[j]=='-'||a[i].str[j]>='A'&&a[i].str[j]<='Y')
> {
> for(unsigned int k=j;k<strlen(a[i].str);k++)
> a[i].str[k]=a[i].str[k+1];
> j--;
> }
> }
> }
> }
> int main()
> {
> int n=0,count=0,flag=0,i=0,j=0;
> unsigned int k=0,f=0;
> cin>>n;
> for(i=0;i<n;i++)
> cin>>s[i].str;
> change(s,n);
> qsort(s,n,sizeof(s[0]),cmp);//排序
> for(i=0;i<n;i++)//找相等的res[][0]记录相等的下标,res[][1]记录相同是个数
> {
> if(strcmp(s[i].str,s[i+1].str)==0)
> {
> res[count][0]=i;
> res[count][1]++;
> flag=1;
> }
> else
> {
> if(flag==1)
> res[count][1]++;
> count++;
> flag=0;
> }
> }
//输出
> if(count==n)
> cout<<"No duplicates."<<endl;
> else
> {
> for(i=0;i<count;i++)
> {
> flag=0;
> if(res[i][0]||res[i][0]==0&&i==0)
> for(f=0;f<strlen(s[res[i][0]].str);f++)
> {
> if(f==3)
> cout<<'-';
> flag=1;
> cout<<s[res[i][0]].str[f];
> }
> if(flag==1)
> cout<<" "<<res[i][1]<<endl;
> }
> }
> return 0;
>
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator