CCF认证练习代码保存

2016.12

①求中间数

代码:

#include<stdio.h>
struct index
{
 int big;
 int small;
 int key;
}a[1001];
int main()
{
 int number;
 int  i, j;
 int count = 0;
 int result;
 scanf_s("%d\n",&number);
 for (i = 1; i <= number; i++)
 {
  scanf_s("%d", &a[i].key);
 }
 for (i = 1; i <= number; i++)
  for (j = 1; j <= number; j++)
  {
   if (a[j].key > a[i].key)
    a[i].big++;
   else if (a[j].key < a[i].key)
    a[i].small++;
  }
 for (i = 1; i <= number; i++)
 {
  if (a[i].big == a[i].small)
  {
   result=a[i].key;
   count++;
  }   
 }
 if (count == 0)
  printf("-1\n");
 else
  printf("%d\n", result);
 return 0;
}

②求税前工资

#include<stdio.h>
int main()
{
 int t,s,ss;
 int a;
 scanf_s("%d",&t);
 for (s = 100; s <= 3500; s = s + 100)
 {
  if (s == t)
  {
   printf("%d\n", s);
   break;
  }
 }
 for (s = 3600; s <= 5000; s = s + 100)
 {
  a = s - 3500;
  ss = s - a * 3 / 100;
  if (ss == t)
  {
   printf("%d\n", s);
   break;
  }
 }
 for (s = 5100; s <= 8000; s = s + 100)
 {
  a = s - 4500;
  ss = s - 45 - a/ 10;
  if (ss == t)
  {
   printf("%d\n", s);
   break;
  }
 }
 for (s = 8100; s <= 12500; s = s + 100)
 {
  a = s - 3500;
  ss = s - 345 - (a - 4500) / 5;
  if (ss == t)
  {
   printf("%d\n", s);
   break;
  }
 }
 for (s = 12600; s <= 38500; s = s + 100)
 {
  a = s - 3500;
  ss = s - 1245- (a - 9000) / 4;
  if (ss == t)
  {
   printf("%d\n", s);
   break;
  }
 }
 for (s = 38600; s <= 58500; s = s + 100)
 {
  a = s - 3500;
  ss = s - 7745 - (a - 35000) * 3 / 10;
  if (ss == t)
  {
   printf("%d\n", s);
   break;
  }
 }
 for (s = 58600; s <= 83500; s = s + 100)
 {
  a = s - 3500;
  ss = s - 13745 - (a - 55000) * 35 / 100;
  if (ss == t)
  {
   printf("%d\n", s);
   break;
  }
 }
 for (s = 83600; s <= 154400; s = s + 100)
 {
  a = s - 3500;
  ss = s - 22495 - (a - 80000) * 45 / 100;
  if (ss == t)
  {
   printf("%d\n", s);
   break;
  }
 } 
 return 0;
}

2016年5月

#include<stdio.h>
int main()
{
 int days;
 int a[1001];
 int i, j;
 scanf("%d\n",&days);
 for (i = 1; i <= days; i++)
  scanf("%d",&a[i]);
 int max = 0;
 int b, c;
 for (i = 1; i <= (days-1); i++)
  {
   j = i + 1;
   if (a[i] < a[j])
   {
    b = a[j] - a[i];
    if (b > max)
    {
     max = b;
     c = i;
    }
   }
   else if (a[i] > a[j])
   {
    b = a[i] - a[j];
    if (b > max)
    {
     max = b;
     c = i;
    }
   }
  }
 printf("%d\n",max);
 return 0;
}

②购买车票系统模拟

 

#include<stdio.h>
int book[21][6];
struct index
{
 int ticketnumber;
 int seat[6];
}a[101];
int seek(int t)
{
 int i, j, k; 
 int sum ;
 for (i = 1; i <= 20; i++)
  for (j = 1; j <= 5; j++)
  {
   sum = 0;
   if (book[i][j] == 0)
   {
    for (k = j; k <= 5; k++)
    {
     if (book[i][k] == 0)
      sum++;
    }
    if (a[t].ticketnumber <= sum)
    {
     for (k = 1; k <= a[t].ticketnumber; k++)
     {
      a[t].seat[k] = 5 * i - 4 + j - 1 + k - 1;
      book[i][j + k - 1] = 1;
     }
     return 0;
    }
    else
    {
     j = 5;
     continue;
    }
   }
  }
   if (a[t].seat[1]==0)
   {
    int record = 0;
    for (i = 1; i <= 20; i++)
     for (j = 1; j <= 5; j++)
     {
      if (book[i][j] == 0)
      {
       record++;
       if (record <= a[t].ticketnumber)
       {
        a[t].seat[record] = 5 * i - 4 + j - 1;
        book[i][j] = 1;
       }
       else
        return 0;
      }
     }
   }
  
 return 0;
}
int main()
{
 int n,m,p; 
 scanf_s("%d\n",&n);
 for (m = 1; m <= n; m++)
  scanf_s("%d", &a[m].ticketnumber);
 for (m = 1; m<= n; m++)
  seek(m);
 for (m = 1; m <= n; m++)
  for (p = 1; p <= a[m].ticketnumber; p++)
  {
   printf("%d ", a[m].seat[p]);
   if (p == a[m].ticketnumber)
    printf("\n");
  }
 getchar(); getchar();
 return 0;
}

 

2016年4月①

#include<stdio.h>
int main()
{
 int n,sum;
 scanf("%d",&n);
 if (n)
  sum = n / 1000000000 + (n % 1000000000) / 100000000 + (n % 1000000000 % 100000000) / 10000000 + (n % 1000000000 % 100000000 % 10000000) / 1000000 + (n % 1000000000 % 100000000 % 10000000 % 1000000) / 100000 + (n % 1000000000 % 100000000 % 10000000 % 1000000 % 100000) / 10000 + (n % 1000000000 % 100000000 % 10000000 % 1000000 % 100000 % 10000) / 1000 + (n % 1000000000 % 100000000 % 10000000 % 1000000 % 100000 % 10000 % 1000) / 100 + (n % 1000000000 % 100000000 % 10000000 % 1000000 % 100000 % 10000 % 1000 % 100) / 10 + (n % 1000000000 % 100000000 % 10000000 % 1000000 % 100000 % 10000 % 1000 % 100 % 10);
 else
     sum = 0;
 printf("%d\n", sum);
 return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值