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

咋回事?cin函数可以用,scanf函数就不行!高手?呼叫高手!

Posted by guowangguilai at 2008-04-12 18:21:26 on Problem 1002
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
int cmp(const void* p1, const void* p2)
{
 return *(long int *)p1 - *(long int *)p2;
}
int main()
 {
  int n,i,j,temp,flag=1;
  cin>>n;
  char **tel;
  tel=new char*[n];
 for(i=0;i<n;i++)
 tel[i]=new char[8];
 long int *num=new long int[n];
 for(i=0;i<n;i++)num[i]=0;
  for(i=0;i<n;i++)//这两重循环将输入的字符转换成long int;
   for(j=0;j<7;j++)
   {
 cin>>tel[i][j];//这句话与下面这句
//scanf("%1c",&tel[i][j]);//这句话跟上面的那句不是作用一样吗?为啥会一个结果正确,一个不正确!好奇怪!
    if(tel[i][j]=='-'){j--;continue;}
    else if((tel[i][j]<'Q')&&(tel[i][j]>='A'))temp=(tel[i][j]-'A')/3+2;
    else if((tel[i][j]>'Q')&&(tel[i][j]<'Z')) temp=(tel[i][j]-'A'-1)/3+2;
    else temp=(tel[i][j]-'0');
    num[i]=num[i]*10+temp;
   }
   
  
qsort(num, n, sizeof(long int), cmp);//快排,将n个数字排序


for(i=0;i<n-1;i++) if(num[i]==num[i+1])
{ flag=0;
 temp=1;
   for(j=i;(j<n-1)&&num[j]==num[j+1];j++)
  temp++;
 printf("%03d-%04d %d\n",num[i]/10000,num[i]%10000,temp);
  i=i+temp-1;
}
}

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