1. 随意组合 

小明被绑架到X星球的巫师W那里。当时,W正在玩弄两组数据 (2 3 5 8) 和

(1 4 6 7),他命令小明从一组数据中分别取数与另一组中的数配对,共配成4对

(组中的每个数必被用到)。

小明的配法是:{(8,7),(5,6),(3,4),(2,1)}

巫师凝视片刻,突然说这个配法太棒了!

因为:

每个配对中的数字组成两位数,求平方和,无论正倒,居然相等:

87^2 + 56^2 + 34^2 + 21^2 = 12302

78^2 + 65^2 + 43^2 + 12^2 = 12302

小明想了想说:“这有什么奇怪呢,我们地球人都知道,随便配配也可以

啊!”

{(8,6),(5,4),(3,1),(2,7)}

86^2 + 54^2 + 31^2 + 27^2 = 12002

68^2 + 45^2 + 13^2 + 72^2 = 12002

巫师顿时凌乱了。。。。。

请你计算一下,包括上边给出的两种配法,巫师的两组数据一共有多少种配

对方案具有该特征。

配对方案计数时,不考虑配对的出现次序。

就是说:{(8,7),(5,6),(3,4),(2,1)}与{(5,6),(8,7),(3,4),(2,1)}是同一种

方案。

运行代码

include <stdio.h>

int main(){

int m[]={2,3,5,8};

int n[]={1,4,6,7};

int a=0,b=0,c=0,d=0,num=0,x,y;

//for循环嵌套,四个位置将四个数遍历一次;

for(a=0;a<4;a++){

for(b=0;b<4;b++){

if(a==b)

b++;

for(c=0;c<4;c++){

while(c==a||c==b){

c++;

}

for(d=0;d<4;d++){

while(d==a||d==b||d==c){

d++;

}

x=(m[0]*10+n[a])*(m[0]*10+n[a])+(m[1]*10+n[b])*(m[1]*10+n[b])+(m[2]*10+n[c])*(m[2]*10+n[c])+(m[3]*10+n[d])*(m[3]*10+n[d]);

y=(n[a]*10+m[0])*(n[a]*10+m[0])+(n[b]*10+m[1])*(n[b]*10+m[1])+(n[c]*10+m[2])*(n[c]*10+m[2])+(n[d]*10+m[3])*(n[d]*10+m[3]);

if(x==y){

num++;

}

}

}

}

}

printf("%d",num);

}

3. palindrom

Statement of the Problem

We say that a number is a palindrom if it is the sane when read from left to right or

from right to left. For example, the number 75457 is a palindrom.

Of course, the property depends on the basis in which is number is represented. The

number 17 is not a palindrom in base 10, but its representation in base 2 (10001) is a

palindrom.

The objective of this problem is to verify if a set of given numbers are palindroms in

any basis from 2 to 16.

Input Format

Several integer numbers comprise the input. Each number 0 < n < 50000 is given in

decimal basis in a separate line. The input ends with a zero.

Output Format11

Your program must print the message Number i is palindrom in basis where I is the

given number, followed by the basis where the representation of the number is a

palindrom. If the number is not a palindrom in any basis between 2 and 16, your

program must print the message Number i is not palindrom.

回文数

运行代码:

#include <stdio.h>

#include <stdlib.h>

int main(){

int n=1,m=1,k=0,j=0,x,y;

int num[150];

while(n!=0){

scanf("%d",&n);

if(n==0)exit(0);

for(int i=2;i<=16;i++){

k=0;

m=1;

x=n;

while(m!=0){

m=x/i;

num[k]=x%i;

k++;

x=m;

}

y=k;

k=k-1;

for(j=0;j<y/2;j++){

if(num[j]==num[k]){

k--;

}

}

if((y-k-1)==y/2&&n>i){

printf("Number %d is palindrom in basis ",n);

for(int s=y-1;s>=0;s--){

printf("%d",num[s]);

}

printf("\n");

}else if(i==2){

printf("Number %d is not a palindrom\n",n);

break;

}

}

}

}

4. 电话号码 

辉子最近接到了一个棘手的任务,他们公司有一个电话簿,但是这是一个奇

怪的电话簿,因为它不是用数字记录电话号码,而是用数字键上所对应的字母来

记录电话号码(

2-abc,3-def,4-ghi,5-jkl,6-mno,7-pqrs,8-tuv,9-wxyz),电话号

码只有11位。现在你的任务就是帮辉子写一个程序来把这些字母的电话号码转化

成数字的电话号码。

输入:

第一行输入一个正整数T(0<T<=100),表示测试数据的组数,每组测试数据只

有一行,输入一串字符(字符长度为11)。

输出:

每组输出占一行,输出数字的电话号码。

运行代码

#include <stdio.h>

#include <stdlib.h>

int main(){

//判断用户输入是否正确;

int t=2,j=0,i=0;

printf("请输入一百以内的数:\n");

scanf("%d",&t);

if(t<0||t>100){

printf("输入的数据有误");

exit(0);

}

char num[1100];

for(i=0;i<t*11+1;i++){

scanf("%c",&num[i]);

}

for(j=0;j<t;j++){

for(i=11*j;i<11*(j+1)+1;i++){

if(num[i]=='a'||num[i]=='b'||num[i]=='c'){

printf("2");

}else if(num[i]=='d'||num[i]=='e'||num[i]=='f'){

printf("3");

}else if(num[i]=='g'||num[i]=='h'||num[i]=='i'){

printf("4");

}else if(num[i]=='j'||num[i]=='k'||num[i]=='l'){

printf("5");

}else if(num[i]=='n'||num[i]=='m'||num[i]=='o'){

printf("6");

}else if(num[i]=='p'||num[i]=='q'||num[i]=='r'||num[i]=='s'){

printf("7");

}else if(num[i]=='t'||num[i]=='u'||num[i]=='v'){

printf("8");

}else if(num[i]=='w'||num[i]=='x'||num[i]=='y'||num[i]=='z'){

printf("9");

}

}

printf("\n");

}

}

随意组合、palindorm、电话号码 程序设计相关推荐

  1. 2016年第七届蓝桥杯C/C++ A组国赛 —— 第一题:随意组合

    标题:随意组合 小明被绑架到X星球的巫师W那里. 其时,W正在玩弄两组数据 (2 3 5 8) 和 (1 4 6 7) 他命令小明从一组数据中分别取数与另一组中的数配对,共配成4对(组中的每个数必被用 ...

  2. 用三极管制作的三色LED循环灯,灯珠颜色及排列可随意组合

    本文介绍三色LED循环灯采用三极管分立元件制作,简单易制,不需调试,并且成本低廉.这种LED循环灯的灯珠颜色及排列可以根据自己的需要来随意组合.该灯可以作为装饰灯,或用来制作会发光的创意盆栽. 原理图 ...

  3. Word中的通配符随意组合进行批量替换或删除某些内容

    长文档需要批量修改或删除某些内容的时候,我们可以利用Word中的通配符来搞定这一切,当然,前提是你必须会使用它.通配符的功能非常强大,能够随意组合替换或删除我们定义的规则内容,下面易老师就分享一些关于 ...

  4. JS验证用户名必须以字母(不区分大小写)、数字、下划线(_)随意组合的字符

    写法一: <script type="text/javascript"> function checkuid(){var obj = document.getEleme ...

  5. [回溯系列] 组合总和+电话号码(day25)

    LC216 组合总和3 找出所有相加之和为 n 的 k 个数的组合,且满足下列条件: 1. 只使用数字1到9:2. 每个数字 最多使用一次. 返回所有可能的有效组合的列表 .组合可以以任何顺序返回 c ...

  6. day21组合III电话号码的字母组合

    回溯的相关题目,有点难度. 1.力扣216(组合III) 本题基于昨天的组合问题,只是把终止条件进行了改变,当数组长度为长度为k时,并且和为n时才将路径存进结果集中,其他步骤和上个题一样. List& ...

  7. add(1)(2),add(1,2)(3)随意长度随意组合的完美解决

    add(1)(2),add(1,2)(3)随意长度组合的完美解决 知识点:柯里化,toString function add () {let args=[...arguments]function s ...

  8. 代码随想录第二十五天|组合、电话号码的字母组合

    代码随想录第二十五天|216.17不熟 Leetcode 216. 组合总和 III Leetcode 17. 电话号码的字母组合 Leetcode 216. 组合总和 III 题目链接: 组合总和 ...

  9. 下一步工作,尽量将代码整理归拢成可以随意组合拆装的代码块。

    在例子中,每个代码区域,每个参数做什么,都写清楚.届时,将直接将例子拖入到工程中然后根据例子改改即可使用.

最新文章

  1. .ccz 批量转换为 .png
  2. 搬砖到年薪百万,是怎样的一种体验?
  3. RabbitMQ管理(1)——多租户与权限
  4. 如何知道iframe文件下载download完成
  5. 运维祈求不宕机_[国庆特辑] 程序员应该求谁保佑才能保证不宕机?
  6. leetcode 109 --- 有序链表变成二叉搜索树
  7. python定义集合_Python - 集合
  8. PHP 三种方式实现链式操作
  9. burpsuite字典破解密码
  10. Git使用ssh方式下载代码
  11. 微信小程序怎么设置服务器上,如何为微信小程序设置服务器地址?-微信小程序服务器诗...
  12. Android多媒体相关框架
  13. iOS开发学习之大牛们的博客
  14. 江南时报:百度有啊命名堪比可口可乐
  15. 测试点 - 发朋友圈
  16. L130被围绕的区域
  17. 文件“无法删除”的处理方法
  18. 玩客云 虚拟服务器设置,玩客云刷 Linux 系统后遇到的问题和设置固定 IP
  19. 【JavaSE】多态数组的使用
  20. 解决 ERROR 1044 (42000): Access denied for user ‘‘@‘localhost‘ to database ‘mysql‘

热门文章

  1. RabbitMQ --- 惰性队列、MQ集群
  2. qqext(QQ2012显IP外挂)V1022 绿色版
  3. TCP流量控制和拥塞控制 最新网狐荣耀版源码下载
  4. 每日蓝桥-基础练习 字母图形
  5. 如何在本地上次文件到GitHub
  6. 怎么注册不需要实名认证的.com域名?
  7. 关于软件和软件工程师
  8. 贪心算法之——摘枇杷(nyoj680)(贪心+二分搜索)
  9. 想学SEM培训就来找网优谷
  10. Kafka-Broker Spread,Broker Skewed,Broker Leader Skewed指标含义