C语言 匪警请拨110,即使手机欠费也可拨通!为了保障社会秩序,保护人民群众生命财产安全
答案:3 悬赏:0 手机版
解决时间 2021-03-22 23:29
- 提问者网友:你独家记忆
- 2021-03-22 13:54
C语言 匪警请拨110,即使手机欠费也可拨通!为了保障社会秩序,保护人民群众生命财产安全
最佳答案
- 五星知识达人网友:woshuo
- 2021-03-22 14:19
#include
#include
#define n 9
int a[n] = {1,2,3,4,5,6,7,8,9} ;
int oper[n];
void Print(int a[],int b[]){
int i,j;
for(i = 0;i < n;i++){
printf("%d",a[i]);
if( oper[i] != 0 && i + 1 < n){
if(oper[i] == 1)
printf("+");
else
printf("-");
}
}
printf("=110\n");
}
int main(){
int i,j,k,temp,nextoper,s = 0;
int number,sum,count = 0;
for(i = 0;i < pow(3,n);i++){
temp = i;
sum = 0;
nextoper = 1;
for(j = 0; j < n;j++){
oper[j] = temp % 3;
temp /= 3;
}
for(j = 0;j < n;j++){
number = 0;
if(oper[j] == 0 && j + 1 < n){
count++;
continue;
}
else{
for(k = 0;k <= count;k++){
number = number * 10;
number += a[j - count + k];
}
if( nextoper == 1)
sum += number;
else
sum -=number;
count = 0;
nextoper = oper[j];
}
}
if(sum == 110){
Print(a,oper);
s ++;
}
}
printf("%d",s);
}
#include
#define n 9
int a[n] = {1,2,3,4,5,6,7,8,9} ;
int oper[n];
void Print(int a[],int b[]){
int i,j;
for(i = 0;i < n;i++){
printf("%d",a[i]);
if( oper[i] != 0 && i + 1 < n){
if(oper[i] == 1)
printf("+");
else
printf("-");
}
}
printf("=110\n");
}
int main(){
int i,j,k,temp,nextoper,s = 0;
int number,sum,count = 0;
for(i = 0;i < pow(3,n);i++){
temp = i;
sum = 0;
nextoper = 1;
for(j = 0; j < n;j++){
oper[j] = temp % 3;
temp /= 3;
}
for(j = 0;j < n;j++){
number = 0;
if(oper[j] == 0 && j + 1 < n){
count++;
continue;
}
else{
for(k = 0;k <= count;k++){
number = number * 10;
number += a[j - count + k];
}
if( nextoper == 1)
sum += number;
else
sum -=number;
count = 0;
nextoper = oper[j];
}
}
if(sum == 110){
Print(a,oper);
s ++;
}
}
printf("%d",s);
}
全部回答
- 1楼网友:酒醒三更
- 2021-03-22 14:38
对啊, 你说的不是废话, 110就是欠费也能打啊.追问学过编程吗??这是一道题目追答啥.......俺学过~~~编程嘛~~~俺学过~~~编程嘛~~~简单~~~~
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯