51nod 1182 1001

寒假作业 51nod 1182
http://www.51nod.com/Challenge/Problem.html#!#problemId=1182

#include<stdio.h>
#include<string.h>
#include<ctype.h>
void sort(int a[])
{
 int i,j,t;
 for(i=0;i<27;i++)
 for(j=i+1;j<27;j++)
 {
  if(a[i]<a[j])
  {
   t=a[i];
   a[i]=a[j];
   a[j]=t;
  }
 }
}
int main(void)
{
 int i=0,j,k,l,o;
 char ch,s;
 int a[27]={0};
 while(scanf("%c",&s), s - '\n')
 {
  s=toupper(s);
  a[s-65]++;
 
 }
 sort(a);
 int sum=0;
 l=26;
 for(i=0;i<27;i++)
 {
  sum += l*a[i];
  l--;
 }
 printf("%d",sum);
 return 0;
} 

51nod 1001
http://www.51nod.com/Challenge/Problem.html#!#problemId=1001

#include<stdio.h>
#include<string.h>
#include<ctype.h>
void  sort( int a[], int low,  int high)
{
   int i,j,temp;
  i=low;
  j=high;
  temp=a[i];
  if(low<high)
  {
  while(i<j)
  {
    while(i<j && a[j]>=temp)
    {
      j--;
    }
    a[i]=a[j];
    while(i<j && a[i]<=temp)
    {
      i++;
    }
    a[j]=a[i];
  }
  a[i]=temp;
  sort(a,low,i-1);
  sort(a,j+1,high);
  }
  else
  {
    return ;
  }
}
int main(void)
{
 int i=0,j,k,l,o=0;
 int n,m;
 int a[60050];
 scanf("%d %d",&k,&n);
 for(i=0;i<n;i++)
 {
  scanf("%d",&a[i]);
 }
 sort(a,0,i-1);
 for(i=0;i<n-1;i++)
 for(j=i+1;j<n;j++)
 {
  if(a[i]+a[j] == k)
  {
   printf("%d %d\n",a[i],a[j]);
   o=1;
  }
 }
 if(o==0)
 {
  printf("No Solution");
 }
 return 0;
} 

猜你喜欢

转载自blog.csdn.net/qq_44009311/article/details/86614314