摘要: 例题 3-1 Tex中的引号 在TeX中,左引号是”””,右引号是““”。输入一篇包含双引号的文章,你的任务是把它转换成TeX的格式。 样例输入: “To be or not to be,”quoth the Bard,”that is the question”. 样例输出:... 阅读全文
posted @ 2015-07-14 10:47 Traim304 阅读(461) 评论(0) 推荐(0) 编辑
摘要: 习题 3-4 竖式问题 找出所有形如abc*de(三位数乘以两位数)的算式,使得在完整的竖式中,所有数字都属于一个特定的数字集合。输入数字集合(相邻数字之间没有空格),输出所有竖式。每个竖式前应有编号,之后应有一个空行。最后输出解的总数。具体格式见样例输出(为了便于观察,竖式中的空格改用小数点显示... 阅读全文
posted @ 2015-07-10 18:55 Traim304 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 程序 3-1 将不超过100个数逆序输出#includeint main(){ int const MAXN = 105; int a[MAXN]; int n = 1, x = 0; // //注意头疼的边界问题 // whil... 阅读全文
posted @ 2015-07-10 15:38 Traim304 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 习题 2-1 打印出所有的“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。 例如:153是一个“水仙花数”,因为153=13+53+33。程序 2-1#includeint main(){ int i = 100; while (i int main(){... 阅读全文
posted @ 2015-07-10 10:58 Traim304 阅读(1034) 评论(0) 推荐(0) 编辑
摘要: 例2-4 阶乘之和 输入n,计算S = 1! + 2! +3! +……+ n!的末6位(不含前导0)。n int main(){ int n; scanf("%d", &n); int sum = 0; int i = 1; while (i #includeint ... 阅读全文
posted @ 2015-07-03 19:46 Traim304 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 例题 2-2 3n+1问题 猜想:对于任意大于1的自然数n若n为奇数,则将n变为3n+1,否则变为n的一半。经过若干次的变换,一定会使n变为1。 例如3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 ->1。 输入n,输出变换的次数。n int main(){ int ... 阅读全文
posted @ 2015-07-03 16:45 Traim304 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 程序 2-1 输出1,2,3,4,5,……,n的值#includeint main(){ int n; scanf("%d", &n); int i = 1; for (; i #includeint main(){ int a, b; for (a = 1; a... 阅读全文
posted @ 2015-07-02 21:00 Traim304 阅读(295) 评论(0) 推荐(0) 编辑
摘要: 例题 1-4 鸡兔同笼 已知鸡和兔的总数量为n, 总腿数为m。输入 n 和 m,依次输出鸡的数目和兔的数目。如果无解,输出No answer 样例输入: 14 32 样例输出: 12 2 样例输入: 10 16 样例输出: No answer【分析】 简单的数学问... 阅读全文
posted @ 2015-07-02 13:17 Traim304 阅读(208) 评论(0) 推荐(0) 编辑
摘要: 例题 1-2 三位数反转 输入一个三位数,分离出它的百位,十位和个位数,反转后输出。 样例输入: 127 样例输出: 721程序 1-6 三位数反转(1)1 #include2 int main()3 {4 int n;5 scanf("%d", &n);6 ... 阅读全文
posted @ 2015-07-01 23:00 Traim304 阅读(746) 评论(0) 推荐(0) 编辑
摘要: 要完成人与计算机的交互,有输出就得有输入。c++中输入输出最基本的是cout,cin。c中是printf和scanf。下面关于是scanf的用法:1-4 a + b问题1 #include2 int main()3 {4 int a, b;5 scanf("%d%d", &a, &b... 阅读全文
posted @ 2015-07-01 16:04 Traim304 阅读(173) 评论(0) 推荐(0) 编辑