首页
学习
活动
专区
圈层
工具
发布
29 篇文章
1
PAT (Basic Level) Practice (中文)1047 编程团体赛
2
PAT (Basic Level) Practice (中文)1083 是否存在相等的差
3
PAT (Basic Level) Practice (中文)1082 射击比赛
4
PAT (Basic Level) Practice (中文)1081 检查密码
5
PAT (Basic Level) Practice (中文)1077 互评成绩计算
6
PAT (Basic Level) Practice (中文)1076 Wifi密码
7
PAT (Basic Level) Practice (中文)1064 朋友数
8
PAT (Basic Level) Practice (中文)1063 计算谱半径
9
PAT (Basic Level) Practice (中文)1057 数零壹
10
PAT (Basic Level) Practice (中文)1056 组合数的和
11
PAT (Basic Level) Practice (中文)1042 字符统计
12
PAT (Basic Level) Practice (中文)1041 考试座位号
13
PAT (Basic Level) Practice (中文)1023 组个最小数
14
PAT (Basic Level) Practice (中文)1022 D进制的A+B
15
PAT (Basic Level) Practice (中文)1019 数字黑洞
16
PAT (Basic Level) Practice (中文)1007 素数对猜想
17
PAT (Basic Level) Practice (中文)1091 N-自守数
18
PAT (Basic Level) Practice (中文)1026 程序运行时间
19
PAT (Basic Level) Practice (中文)1061 判断题
20
PAT (Basic Level) Practice (中文)1086 就不告诉你
21
PAT (Basic Level) Practice (中文)1016 部分A+B
22
PAT (Basic Level) Practice (中文)1012 数字分类
23
PAT (Basic Level) Practice (中文)1013 数素数
24
PAT (Basic Level) Practice (中文)1011 A+B 和 C
25
PAT (Basic Level) Practice (中文)1009 说反话
26
PAT (Basic Level) Practice (中文)1008 数组元素循环右移问题
27
PAT (Basic Level) Practice (中文)1006 换个格式输出整数
28
PAT (Basic Level) Practice (中文)1004 成绩排名
29
PAT (Basic Level) Practice (中文)1002 写出这个数

PAT (Basic Level) Practice (中文)1056 组合数的和

1056 组合数的和

给定 N 个非 0 的个位数字,用其中任意 2 个数字都可以组合成 1 个 2 位的数字。要求所有可能组合出来的 2 位数字的和。例如给定 2、5、8,则可以组合出:25、28、52、58、82、85,它们的和为330。

输入格式:

输入在第一行中给出 N(1 < N < 10),随后一行给出 N 个不同的非 0 个位数字。数字间以空格分隔。

输出格式:

输出所有可能组合出来的2位数字的和。

输入样例:

3 2 8 5

输出样例:

330

分析:

1、求出所有可能的两位数组合

代码语言:javascript
复制
void fun1(int *arr,int N)
 {
     int i,j;
     for(i=0;i<N-1;i++)
     {
         for(j=i+1;j<N;j++)
         {
             int temp=arr[i]*10+arr[j];
             if(temp>9) temparr[t++]=temp;  剔除所有不是两位数的数,
         }
     }
 }

2、除去数组 temparr 中重复出现的数

代码语言:javascript
复制
void fun2(int *temparr,int t)
  {
      int i,j;
      for(i=0;i<t-1;i++)
      {
          for(j=i+1;j<t;j++)
          {
              if(temparr[i]<100&&temparr[i]==temparr[j]) temparr[j]=999;
          }
      }
  }

3、求和

代码:

代码语言:javascript
复制
#include<stdio.h>
#include<stdlib.h>

int temparr[1000];
int t=0;
 void fun1(int *arr,int N)
 {
     int i,j;
     for(i=0;i<N-1;i++)
     {
         for(j=i+1;j<N;j++)
         {
             int temp=arr[i]*10+arr[j];
             if(temp>9) temparr[t++]=temp;
         }
     }
 }
  void fun2(int *temparr,int t)
  {
      int i,j;
      for(i=0;i<t-1;i++)
      {
          for(j=i+1;j<t;j++)
          {
              if(temparr[i]<100&&temparr[i]==temparr[j]) temparr[j]=999;
          }
      }
  }
int main()
{
    int N;
    int i;
    int arr1[101];
    int arr2[101];
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d",&arr1[i]);
        arr2[N-1-i]=arr1[i];
    }
    fun1(&arr1,N);
    fun1(&arr2,N);
    fun2(&temparr,t);
    int sum=0;
    for(i=0;i<t;i++)
      if(temparr[i]<100) sum+=temparr[i];
    printf("%d\n",sum);
    return 0;
}
下一篇
举报
领券