| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1175 人关注过本帖
标题:求指教,请各位看看这道题,在国外孤立无援。
只看楼主 加入收藏
hana_flower
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-7-22
结帖率:0
收藏
已结贴  问题点数:20 回复次数:12 
求指教,请各位看看这道题,在国外孤立无援。
Question:

generate two different random integers, s and t, which are different for each message. s is called the start code and t is called the end code.
The value of t is transmitted as the first integer in the encoded output. Then for every integer i in the message, the integer s is sent followed by a
randomly generated sequence L of 1 or more integers that sum to i with the constraint that neither s nor t appears in the sequence.

The entire message is terminated by a single t value. For example, if the message is 3, 21, 5 and the start and end codes are 11 and -91, the message might be transmitted as -91, 11, -1, 5, 2, -3, 11, 21, 11, 4, 0, 1 , -91 (where 3 is represented as -1 + 5 + 2 - 3, 21 is represented as itself and 5 is represented as 4 + 0 + 1).

Non-functional requirements: your program may not use arrays!

Input  
-91 11 -1 5 2 -3 11 21 11 4 0 1 -91

Output
3
21
5
Input
0 1 2 3 4 1 -1 -2 -3 0  

output
9
-6

拜托各位帮帮忙吧,我人在澳洲,刚到这边,没几个会编程的朋友,大部分都是学商科的,这个是学校的作业,我实在是不太明白怎么做。只能求教于网络了。拜托大家
搜索更多相关主题的帖子: generated single different sequence message 
2012-07-22 21:07
随风飘荡
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:208
专家分:598
注 册:2011-9-9
收藏
得分:3 
迷一样的一篇幅英文
2012-07-22 21:27
obstratiker
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:1
帖 子:198
专家分:758
注 册:2011-5-5
收藏
得分:3 
题目的输入是一个数字接一个空格直到输入完毕,这个我不知道怎么实现了
只能做到输入一个数字然后回车再输入下一个数字
输出倒是可以一致
还有题目说最好不用数组,估计还是能用的,将就将就吧

#include <stdio.h>

int main(void)
{
    int a[100];
    int start,end,out=0,i=1;
    scanf("%d",&end);
    a[0]=end;
    do
    {
        scanf("%d",&end);
        a[i]=end;
        i++;
    }while(end!=a[0]);
    printf("\n");
    i=2;
    start=a[1];
    while(a[i]!=end)
    {
        if(a[i]!=start&&a[i]!=end)
        {
            out+=a[i];
            i++;
        }
        else
        {
            printf("%d\n",out);
            i++;
            out=0;
        }
    }
    printf("%d\n",out);
    return 0;
}
2012-07-22 21:45
w995612220
Rank: 5Rank: 5
等 级:职业侠客
威 望:1
帖 子:139
专家分:313
注 册:2012-6-20
收藏
得分:3 
#include <stdio.h>
#define N 5    //N 为输入的数字减1
int main(void)
{
    int a[N];
    int i,z,j,n=0;
    for(i=0;i<N;i++)
    {
        scanf("%d",&z);
        a[i]=z;
        if(a[i]=='#')  break; //以#作为结束标志
    }
   
    for(j=0;j<N-1;j++)
        printf("%d\t",a[j]);
    printf("\n");
}
2012-07-22 22:27
circlemiss
Rank: 2
等 级:论坛游民
帖 子:30
专家分:51
注 册:2012-7-19
收藏
得分:3 
#if 1
#include<stdio.h>
int main(void)
{
    int s,t,i=0,sum;
    printf("Input\n");
    scanf("%d",&t);
    scanf("%d",&s);
    scanf("%d",&sum);
    i=sum;//使第一次赋值不丢失,保持第一次输入的值。
    while(sum!=t)
    {
        scanf("%d",&sum);
        if(sum!=s)
        {
            i+=sum;
        }
        else
        {
            printf("%d\n",i);
            i=0;//输出一个i,让i归0;
        }
    }
    printf("%d\n",i-t);//输入sum的值等于t时退出,这时输出要减去t。
    printf("\n");
    return 0;
}
#endif
2012-07-22 23:50
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:3 
呵呵,凑个热闹
程序代码:
#include<stdio.h>
int main()
{
    int s, t, a = 0, i;
    for(scanf("%d%d", &t, &s); scanf("%d", &i), i != t; a = i != s ? a + i : (printf("%d\n", a), 0));
    printf("%d\n", a);
    return 0;
}

重剑无锋,大巧不工
2012-07-23 00:00
obstratiker
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:1
帖 子:198
专家分:758
注 册:2011-5-5
收藏
得分:0 
以下是引用beyondyf在2012-7-23 00:00:26的发言:

呵呵,凑个热闹
#include
int main()
{
    int s, t, a = 0, i;
    for(scanf("%d%d", &t, &s); scanf("%d", &i), i != t; a = i != s ? a + i : (printf("%d\n", a), 0));
    printf("%d\n", a);
    return 0;
}
版主,太精彩了!可是我不明白为什么for能让人一个数字一个空格的输入直至输入完毕呢?
2012-07-23 00:18
obstratiker
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:1
帖 子:198
专家分:758
注 册:2011-5-5
收藏
得分:0 
以下是引用obstratiker在2012-7-23 00:18:08的发言:

版主,太精彩了!可是我不明白为什么for能让人一个数字一个空格的输入直至输入完毕呢?
哦哦~自己试验了一下,我的理解是,一开始电脑会把在控制台的输入全部放入一个缓冲区,只要程序中有scanf之类的命令,就是依次读取这个缓冲区对吗?
是否printf也有类似的缓冲区?
输入缓冲区是不是和输出缓冲区分开的?
2012-07-23 00:24
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
回复 7楼 obstratiker
这又得说流是怎么回事了。说来话长,总之当键盘作为标准输入流时,你按回车数据才进入标准流。而scanf从流中获取匹配的数据后就返回了,流中未读出的数据还在流里。

呵呵,关于流的概念确实不是很容易就能理解,多自己做些试验感悟吧。

重剑无锋,大巧不工
2012-07-23 00:30
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
回复 8楼 obstratiker
是。准确地讲它们是输入流和输出流(不同的流)。

重剑无锋,大巧不工
2012-07-23 00:32
快速回复:求指教,请各位看看这道题,在国外孤立无援。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016020 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved