博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Street Number (UVA 138)
阅读量:5248 次
发布时间:2019-06-14

本文共 1535 字,大约阅读时间需要 5 分钟。

 Street Numbers 

A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of the street. Every evening she walks her dog by leaving her house and randomly turning left or right and walking to the end of the street and back. One night she adds up the street numbers of the houses she passes (excluding her own). The next time she walks the other way she repeats this and finds, to her astonishment, that the two sums are the same. Although this is determined in part by her house number and in part by the number of houses in the street, she nevertheless feels that this is a desirable property for her house to have and decides that all her subsequent houses should exhibit it.

 

Write a program to find pairs of numbers that satisfy this condition. To start your list the first two pairs are: (house number, last number):

 

6         8        35        49

 

Input and Output

There is no input for this program. Output will consist of 10 lines each containing a pair of numbers, each printed right justified in a field of width 10 (as shown above).

 

View Code
1 /* 2  * Street Number 3  */ 4  5 #include 
6 7 int main(int argc, const char *argv[]) 8 { 9 int m = 3, k = 1;10 int m1, k1;11 int i;12 13 for (i = 0; i < 10; i++) {14 m1 = 3 * m + 8 * k;15 k1 = 3 * k + m;16 m = m1;17 k = k1;18 19 printf("%10d%10d\n", k, (m-1)/2);20 }21 22 return 0;23 }

 

转载于:https://www.cnblogs.com/loulanguju/archive/2013/05/07/3065467.html

你可能感兴趣的文章
Linux中防火墙centos
查看>>
mysql新建用户,用户授权,删除用户,修改密码
查看>>
FancyCoverFlow
查看>>
JS博客
查看>>
如何设置映射网络驱动器的具体步骤和方法
查看>>
ASP.NET WebApi 基于OAuth2.0实现Token签名认证
查看>>
283. Move Zeroes把零放在最后面
查看>>
Visual Studio Code 打开.py代码报Linter pylint is not installed解决办法
查看>>
Python 数据类型
查看>>
17.树的子结构
查看>>
D - Mike and strings
查看>>
S5PV210根文件系统的制作(一)
查看>>
51NOD 1244 莫比乌斯函数之和
查看>>
[bzoj1923]外星千足虫[高斯消元]
查看>>
centos下同时启动多个tomcat
查看>>
slab分配器
查看>>
数据清洗
查看>>
【读书笔记】C#高级编程 第三章 对象和类型
查看>>
Struts2工作原理
查看>>
针对sl的ICSharpCode.SharpZipLib,只保留zip,gzip的流压缩、解压缩功能
查看>>