NOJ答案c++版

合集下载

全国大学生英语竞赛c级试题及答案

全国大学生英语竞赛c级试题及答案

全国大学生英语竞赛c级试题及答案全国大学生英语竞赛(National English Contest for College Students,简称NECCS)是中国大学生英语综合能力的一项重要竞赛。

C级试题主要面向非英语专业的本科生。

以下是一份模拟的C级试题及答案,仅供参考。

全国大学生英语竞赛C级模拟试题Part I Listening Comprehension (30 points)Section A (Short Conversations)1. A) The man will go to the library.B) The woman will go to the library.C) Neither of them will go to the library.D) Both of them will go to the library.[Answer: B]Section B (Long Conversations)2. What does the woman suggest doing?A) Going to the beach.B) Staying at home.C) Going to the movies.D) Visiting a museum.[Answer: C]Section C (Passages)3. What is the main idea of the passage?A) The importance of education.B) The benefits of traveling.C) The advantages of technology.D) The impact of globalization.[Answer: A]Section D (Compound Dictation)4. Fill in the blanks according to the dictation.[Answer:- Blank 1: opportunities- Blank 2: challenges- Blank 3: essential- Blank 4: communicate- Blank 5: effectively]Part II Reading Comprehension (40 points)Section A (Reading Passages)5. According to the passage, what is the author's opinion on the role of technology in education?A) It is indispensable.B) It is overrated.C) It is a distraction.D) It is unnecessary.[Answer: A]Section B (Reading Passages)6. What can be inferred from the second passage about the future of work?A) It will be dominated by artificial intelligence.B) It will require less human interaction.C) It will be more flexible and remote.D) It will be limited to traditional office settings. [Answer: C]Part III Cloze Test (15 points)7. Fill in the blanks with the appropriate words.[Answer:- Blank 1: however- Blank 2: Despite- Blank 3: potential- Blank 4: benefits- Blank 5: therefore]Part IV Translation (15 points)Section A (English to Chinese)8. Translate the following sentence into Chinese."The rapid development of technology has brought about significant changes in our daily lives."[Answer: 技术快速发展给我们的日常生活带来了重大变化。

全国大学生英语竞赛试题及答案c类

全国大学生英语竞赛试题及答案c类

全国大学生英语竞赛试题及答案c类全国大学生英语竞赛(National English Contest for College Students,简称NECCS)是一项面向全国大学生的英语能力竞赛,旨在提高大学生的英语应用能力。

C类试题主要针对非英语专业本科生。

以下是一份模拟试题及答案,供参考:全国大学生英语竞赛C类模拟试题一、听力理解(共30分)Section A(共10分,每题1分)1. What is the man going to do after work today?A. Go to the gym.B. Go to the library.C. Go home directly.Answers:1. A(以下题目略)二、阅读理解(共30分)Passage 1The article discusses the importance of environmental protection and the role of individuals in reducing pollution.Questions:21. What is the main idea of the passage?A. The significance of individual actions in environmental protection.B. The role of governments in environmental policies.C. The impact of industrialization on the environment.Answers:21. A(以下题目及文章略)三、词汇和语法(共20分)Section A(共10分,每题1分)26. The company is expected to ________ a new product line next month.A. launchB. landC. latchAnswers:26. A(以下题目略)四、完形填空(共20分)In this section, there is a passage with blanks. For each blank, there are four choices marked A, B, C, and D. Choosethe one that best fits the context of the passage.Example:... The project was a success, largely due to the ________ of the team members.A. collaborationB. competitionC. communicationD. confrontationAnswer:... The project was a success, largely due to the A. collaboration of the team members.(以下题目略)五、翻译(共20分)Section A Chinese to English translation (10 points) Translate the following sentence into English:27. 随着科技的发展,我们的生活变得越来越便利。

全国大学生英语竞赛c类样题参考答案

全国大学生英语竞赛c类样题参考答案

---------------------------------------------------------------最新资料推荐------------------------------------------------------ 2016年全国大学生英语竞赛C类样题参考答案2016 National English Competition for College Students(Level C - Sample)参考答案及评分标准Part I. Listening Comprehension (30 marks) Section A (5 marks) 1—5 CBABD Section B (10 marks) 6—10 CBADC 11—15 CDACB Section C (5 marks) 16—20 BDBBC Section D (10 marks) 21. second largest 22. spirals to 23. geographic location 24. cultural influences 25. dates back to 26. economic revival 27. flourished in 28. multi-faceted and diverse 29. modern and enterprising 30. a chimney Part II Vocabulary, Grammar & Culture (15 marks) Section A Vocabulary & Grammar (10 marks) 31—35 CDBAA 36—40 BCACB Section B Culture (5 marks) 41—45 BBACA Part III Cloze (10 marks) 46. movement 47. included 48. contrast 51. harmony 52. others 53. individualists 49. information 54. descent 50. back 55. intellectuallyPart IV Reading Comprehension (35 marks) Section A 56. T 57. F 58. F 59. F 60.F Section B 61—65 ACBDE Section C (10 marks) 66. They notice the subjects that most people don’t. 67. Artistry can be learned and developed through reading or taking lessons. 68. Understand the difference it makes when you remove the irrelevant and select only what really matters while taking a picture. - 1 -1/ 1469. Take more exercises. 70. To learn from experience and improve marks out the photographer from others. Section D (10 marks) 71. different 72. constructing/building 73. agree 74. similarities 75. speculationPart V Translation (15marks) Section A (5marks) 76. 教育是民生改善的来源,传承文明的载体。

第10届蓝桥杯大学生c组试题及答案

第10届蓝桥杯大学生c组试题及答案

第10届蓝桥杯大学生c组试题及答案第10届蓝桥杯大学生C组试题及答案1. 选择题- 1.1 以下哪个选项是C语言中合法的变量名?- A. 2variable- B. variable2- C. variable_2- D. variable-2- 答案:C- 1.2 以下哪个选项是C语言中合法的常量?- A. 0x1A- B. 0x1A.5- C. 0x1A.0- D. 0x1A.5F- 答案:A2. 填空题- 2.1 请填写以下C语言代码中缺失的变量类型,使得代码能够正确编译:```cint main() {____ a = 10;printf("%d", a);return 0;}```- 答案:int- 2.2 请填写以下C语言代码中缺失的运算符,使得代码能够正确编译并输出预期结果:```cint main() {int a = 20, b = 10;printf("%d", a ____ b);return 0;}```- 答案:/3. 编程题- 3.1 编写一个C语言程序,实现以下功能:输入一个整数n,输出n的阶乘。

- 答案:```c#include <stdio.h>long factorial(int n) {if (n == 0) return 1;return n * factorial(n - 1);}int main() {int n;scanf("%d", &n);printf("%ld", factorial(n));return 0;}```- 3.2 编写一个C语言程序,实现以下功能:输入一个字符串,输出其反转后的字符串。

- 答案:```c#include <stdio.h>#include <string.h>int main() {char str[100], reversed[100];scanf("%s", str);int length = strlen(str);for (int i = 0; i < length; i++) {reversed[i] = str[length - 1 - i];}reversed[length] = '\0';printf("%s", reversed);return 0;}```4. 简答题- 4.1 请简述C语言中指针的概念及其用途。

c程序设计第二版谭浩强课后答案

c程序设计第二版谭浩强课后答案

c程序设计第二版谭浩强课后答案C程序设计第二版是谭浩强教授编写的一本广泛使用的计算机程序设计教材,它以C语言为基础,深入浅出地介绍了程序设计的基本概念、语法规则和编程技巧。

这本书的课后习题对于加深理解C语言的知识点非常有帮助。

以下是部分课后习题的答案,供参考:第一章程序设计和C语言概述1. 问题一:简述程序设计的基本步骤。

- 答案:程序设计的基本步骤包括需求分析、设计、编码、测试和维护。

2. 问题二:C语言的主要特点是什么?- 答案:C语言的主要特点包括简洁高效、结构化、可移植性、丰富的运算符、灵活的数据类型和内存管理能力。

第二章 C语言程序的结构1. 问题一:C语言程序的基本结构是什么?- 答案:C语言程序的基本结构包括预处理指令、函数定义和主函数。

2. 问题二:什么是函数?C语言中函数的定义规则是什么?- 答案:函数是一段具有特定功能的代码块,可以被重复调用。

C 语言中函数的定义规则包括返回类型、函数名和参数列表。

第三章数据类型、运算符和表达式1. 问题一:C语言中的基本数据类型有哪些?- 答案:C语言中的基本数据类型包括整型(int)、字符型(char)、浮点型(float和double)。

2. 问题二:算术运算符有哪些?它们的优先级是怎样的?- 答案:算术运算符包括加(+)、减(-)、乘(*)、除(/)和模(%)。

它们的优先级从高到低依次是乘除、模、加减。

第四章控制语句1. 问题一:C语言中的条件语句有哪些?- 答案:C语言中的条件语句包括if语句、if...else语句和switch语句。

2. 问题二:循环语句有哪些?它们的基本结构是什么?- 答案:C语言中的循环语句包括while循环、do...while循环和for循环。

它们的基本结构是初始化、条件判断和迭代。

第五章数组1. 问题一:什么是数组?数组的声明方式有哪些?- 答案:数组是相同数据类型元素的集合。

数组的声明方式包括在函数内部声明和全局声明。

c语言程序设计现代方法(第二版)习题答案(5篇)

c语言程序设计现代方法(第二版)习题答案(5篇)

c语言程序设计现代方法(第二版)习题答案(5篇)第一篇:c语言程序设计现代方法(第二版)习题答案Chapter 2 Answers to Selected Exercises 2.[was #2](a)The program contains one directive(#include)and four statements(three calls of printf and one return).(b)Parkinson's Law: Work expands so as to fill the time available for its completion.3.[was #4] #includeint main(void){ int height = 8, length = 12, width = 10, volume;volume = height * length * width;printf(“Dimensions: %dx%dx%dn”, length, width, height);printf(“Volume(cubic inches): %dn”, volume);printf(“Dimensional weight(pounds): %dn”,(volume + 165)/ 166);return 0;} 4.[was #6] Here's one possible program: #include int main(void){ int i, j, k;float x, y, z;printf(“Value of i: %dn”, i);printf(“Value of j: %dn”, j);printf(“Value of k: %dn”, k);printf(“Value of x: %gn”, x);printf(“Value of y: %gn”, y);printf(“Value of z: %gn”, z);return 0;} When compiled using GCC and then executed, this program produced the following output: Value of i: 5618848 Value of j: 0 Value of k: 6844404 Value of x: 3.98979e-34 Value of y: 9.59105e-39 Value of z: 9.59105e-39 The values printed depend on many factors, so the chance that you'll get exactly these numbers is small.5.[was #10](a)is not legal because 100_bottles begins with a digit.8.[was #12] There are 14 tokens: a, =,(, 3, *, q,-, p, *, p,), /, 3, and;.Answers to Selected Programming Projects 4.[was #8;modified] #includeint main(void){ float original_amount, amount_with_tax;printf(“Enter an amount: ”);scanf(“%f”, &original_amount);amount_with_tax = original_amount * 1.05f;printf(“With tax added: $%.2fn”, amount_with_tax);return 0;} The amount_with_tax variable is unnecessary.If we remove it, the program is slightly shorter: #includeint main(void){ float original_amount;printf(“Enter an amount: ”);scanf(“%f”, &original_amount);printf(“With tax added: $%.2fn”, original_amount * 1.05f);return 0;}Chapter 3 Answers to Selected Exercises 2.[was #2](a)printf(“%-8.1e”, x);(b)printf(“%10.6e”, x);(c)printf(“%-8.3f”, x);(d)printf(“%6.0f”, x);5.[was #8] The values of x, i, and y will be 12.3, 45, and.6, respectively.Answers to Selected Programming Projects 1.[was #4;modified] #includeint main(void){ int month, day, year;printf(“Enter a date(mm/dd/yyyy): ”);scanf(“%d/%d/%d”, &month, &day, &year);printf(“You entered the date %d%.2d%.2dn”, year, month, day);return 0;} 3.[was #6;modified] #includeint main(void){ int prefix, group, publisher, item, check_digit;printf(“Enter ISBN: ”);scanf(“%d-%d-%d-%d-%d”, &prefix, &group, &publisher, &item, &check_digit);printf(“GS1 prefix: %dn”, prefix);printf(“Group identifier: %dn”, group);printf(“Publisher code: %dn”, publisher);printf(“Item number: %dn”, item);printf(“Check digit: %dn”, check_digit);/* The five printf calls can be combined as follows:printf(“GS1 prefix: %dnGroup identifier: %dnPublishercode: %dnItem number: %dnCheck digit: %dn”, prefix, group, publisher, item, check_digit);*/return 0;}Chapter 4 Answers to Selected Exercises 2.[was #2] Not in C89.Suppose that i is 9 and j is 7.The value of(-i)/j could be either –1 or –2, depending on the implementation.On the other hand, the value of-(i/j)is always –1, regardless of the implementation.In C99, on the other hand, the value of(-i)/j must be equal to the value of-(i/j).9.[was #6](a)63 8(b)3 2 1(c)2-1 3(d)0 0 0 13.[was #8] The expression ++i is equivalent to(i += 1).The value of both expressions is i after the increment has been performed.Answers to Selected Programming Projects 2.[was #4] #include int main(void){ int n;printf(“Enter a three-digit number: ”);scanf(“%d”, &n);printf(“The reversal is: %d%d%dn”, n % 10,(n / 10)% 10, n / 100);return 0;}Chapter 5 Answers to Selected Exercises 2.[was #2](a)1(b)1(c)1(d)1 4.[was #4](i > j)12, minutes);return 0;} 4.[was #8;modified] #includeint main(void){ int speed;printf(“Enter a wind speed in knots: ”);scanf(“%d”, &speed);if(speed < 1)printf(“Calmn”);else if(speed <= 3)printf(“Light airn”);else if(speed <= 27)printf(“Breezen”);else if(speed <= 47)printf(“Galen”);else if(speed <= 63)printf(“Stormn”);else printf(“Hurricanen”);return 0;} 6.[was #10] #includeint main(void){ int check_digit, d, i1, i2, i3, i4, i5, j1, j2, j3, j4, j5, first_sum, second_sum, total;printf(“Enter the first(single)digit: ”);scanf(“%1d”, &d);printf(“Enter first group of five digits: ”);scanf(“%1d%1d%1d%1d%1d”, &i1, &i2, &i3, &i4, &i5);printf(“Enter second group of five digits: ”);scanf(“%1d%1d%1d%1d%1d”, &j1, &j2, &j3, &j4, &j5);printf(“Enter the last(single)digit: ”);scanf(“%1d”, &check_digit);first_sum = d + i2 + i4 + j1 + j3 + j5;second_sum = i1 + i3 + i5 + j2 + j4;total = 3 * first_sum + second_sum;if(check_digit == 91)% 10))printf(“VALIDn”);else printf(“NOT VALIDn”);return 0;} 10.[was #14] #includeint main(void){ int grade;printf(“Enter numerical grade: ”);scanf(“%d”, &grade);if(grade < 0 || grade > 100){ printf(“Illegal graden”);return 0;}switch(grade / 10){ case 10: case 9: printf(“Letter grade: An”);break;case 8: printf(“Letter grade: Bn”);break;case 7: printf(“Letter grade: Cn”);break;case 6: printf(“Letter grade: Dn”);break;case 5: case 4: case 3: case 2: case 1: case 0: printf(“Letter grade: Fn”);break;}return 0;}Chapter 6 Answers to Selected Exercises 4.[was #10](c)is not equivalent to(a)and(b), because i is incremented before the loop body is executed.10.[was #12] Consider the following while loop: while(…){…continue;… } The equivalent code using goto would have the following appearance: while(…){…goto loop_end;…loop_end:;/* null statement */ } 12.[was #14] for(d = 2;d * d <= n;d++)if(n % d == 0)break;The if statement that follows the loop will need to be modified as well: if(d * d <= n)printf(“%d is divisible by %dn”, n, d);else printf(“%d is primen”, n);14.[was #16] The problem is the semicolon at the end of the first line.If we remove it, the statement is now correct: if(n % 2 == 0)printf(“n is evenn”);Answers to Selected Programming Projects 2.[was #2] #includeint main(void){ int m, n, remainder;printf(“Enter two integers: ”);scanf(“%d%d”, &m, &n);while(n!= 0){ remainder = m % n;m = n;n = remainder;} printf(“Greatest common divisor: %dn”, m);return 0;} 4.[was #4] #includeint main(void){ float commission, value;printf(“Enter value of trade: ”);scanf(“%f”, &value);while(value!= 0.0f){ if(value < 2500.00f)commission = 30.00f +.017f * value;else if(value < 6250.00f)commission = 56.00f +.0066f * value;else if(value < 20000.00f)commission = 76.00f +.0034f * value;else if(value < 50000.00f)commission = 100.00f +.0022f * value;else if(value < 500000.00f)commission = 155.00f +.0011f * value;else commission = 255.00f +.0009f * value;if(commission < 39.00f)commission = 39.00f;printf(“Commission: $%.2fnn”, commission);printf(“Enter value of trade: ”);scanf(“%f”, &value);}return 0;} 6.[was #6] #includeint main(void){ int i, n;printf(“Enter limit on maximum square: ”);scanf(“%d”, &n);for(i = 2;i * i <= n;i += 2)printf(“%dn”, i * i);return 0;} 8.[was #8] #includeint main(void){ int i, n, start_day;printf(“Enter number of days in month: ”);scanf(“%d”, &n);printf(“Enter starting day of the week(1=Sun, 7=Sat): ”);scanf(“%d”, &start_day);/* print any leading “blank dates” */ for(i = 1;i < start_day;i++)printf(“ ”);/* now print the calendar */ for(i = 1;i <= n;i++){ printf(“%3d”, i);if((start_day + i1 && y >= 0 && y <= npass;card++){ rank = hand[card][RANK];suit = hand[card][SUIT];if(hand[card+1][RANK] < rank){ hand[card][RANK] = hand[card+1][RANK];hand[card][SUIT] = hand[card+1][SUIT];hand[card+1][RANK] = rank;hand[card+1][SUIT] = suit;} }/* check for flush */ suit = hand[0][SUIT];for(card = 1;card < NUM_CARDS;card++)if(hand[card][SUIT]!= suit)flush = false;/* check for straight */ for(card = 0;card < NUM_CARDS1 && num_in_rank[0] > 0 && num_in_rank[NUM_RANKS-1] > 0){ straight = true;return;}/* check for 4-of-a-kind, 3-of-a-kind, and pairs */ for(rank = 0;rank < NUM_RANKS;rank++){ if(num_in_rank[rank] == 4)four = true;if(num_in_rank[rank] == 3)three = true;if(num_in_rank[rank] == 2)pairs++;} }/********************************************************** * print_result: Prints the classification of the hand, * * based on the values of the external * * variables straight, flush, four, three, * * and pairs.* **********************************************************/ void print_result(void){ if(straight && flush)printf(“Straight flush”);else if(four)printf(“Four of a kind”);else if(three &&pairs == 1)printf(“Full house”);else if(flush)printf(“Flush”);else if(straight)printf(“Straight”);else if(three)printf(“Three of a kind”);else if(pairs == 2)printf(“Two pairs”);else if(pairs == 1)printf(“Pair”);else printf(“High card”);printf(“nn”);}Chapter 11 Answers to Selected Exercises 2.[was #2](e),(f), and(i)are legal.(a)is illegal because p is a pointer to an integer and i is an integer.(b)is illegal because *p is an integer and &i is a pointer to an integer.(c)is illegal because &p is a pointer to a pointer to an integer and q is a pointer to an integer.(d)is illegal for reasons similar to(c).(g)is illegal because p is a pointer to an integer and *q is an integer.(h)is illegal because *p is an integer and q is a pointer to an integer.4.[was #4;modified] void swap(int *p, int *q){ int temp;temp = *p;*p = *q;*q = temp;} 6.[was #6] void find_two_largest(int a[], int n, int *largest, int *second_largest){ int i;if(a[0] > a[1]){ *largest = a[0];*second_largest = a[1];} else { *largest = a[1];*second_largest = a[0];}for(i = 2;i < n;i++)if(a[i] > *largest){ *second_largest = *largest;*largest = a[i];} else if(a[i] > *second_largest)*second_largest = a[i];}Chapter 12 Answers to Selected Exercises 2.[was #2] The statement is illegal because pointers cannot be added.Here's a legal statement that has the desired effect: middle = low +(highlow)/ 2 is an integer, not a pointer, so it can legally be added to low.4.[was #6] int *top_ptr;void make_empty(void){ top_ptr = &contents[0];}bool is_empty(void){ return top_ptr == &contents[0];}bool is_full(void){ return top_ptr == &contents[STACK_SIZE];}6.[was #10;modified] int sum_array(const int a[], int n){ int *p, sum;sum = 0;for(p = a;p < a + n;p++)sum += *p;return sum;} 13.[was #12;modified] #define N 10double ident[N][N], *p;int num_zeros = N;for(p = &ident[0][0];p <= &ident[N-1][N-1];p++)if(num_zeros == N){ *p = 1.0;num_zeros = 0;} else { *p = 0.0;num_zeros++;} 15.[was #14] int *p;for(p = temperatures[i];p < temperatures[i] + 24;p++)printf(“%d ”, *p);Answers to Selected Programming Projects 1.[was #4](a)#include#define MSG_LEN 80 /* maximum length of message */int main(void){ char msg[MSG_LEN];int i;printf(“Enter a message: ”);for(i = 0;i < MSG_LEN;i++){ msg[i] = getchar();if(msg[i] == 'n')break;} printf(“Reversal is: ”);for(i--;i >= 0;i--)putchar(msg[i]);putchar('n');return 0;}(b)#include#define MSG_LEN 80 /* maximum length of message */int main(void){ char msg[MSG_LEN], *p;printf(“Enter a message: ”);for(p = &msg[0];p < &msg[MSG_LEN];p++){ *p = getchar();if(*p == 'n')break;} printf(“Reversal is: ”);for(p--;p >= &msg[0];p--)putchar(*p);putchar('n');return 0;} 3.[was #8] #include#define MSG_LEN 80 /* maximum length of message */int main(void){ char msg[MSG_LEN], *p;printf(“Enter a message: ”);for(p = msg;p < msg + MSG_LEN;p++){ *p = getchar();if(*p == 'n')break;}printf(“Reversal is: ”);for(p--;p >= msg;p--)putchar(*p);putchar('n');return 0;}Chapter 13 Answers to Selected Exercises 2.[was #2](a)Illegal;p is not a character.(b)Legal;output is a.(c)Legal;output is abc.(d)Illegal;*p is not a pointer.4.[was #4](a)int read_line(char str[], int n){ int ch, i = 0;while((ch = getchar())!= 'n')if(i == 0 && isspace(ch));/* ignore */ else if(i < n)str[i++] = ch;str[i] = '';return i;}(b)int read_line(char str[], int n){ int ch, i = 0;while(!isspace(ch = getchar()))if(i < n)str[i++] = ch;str[i] = '';return i;}(c)int read_line(char str[], int n){ int ch, i = 0;do { ch = getchar();if(i < n)str[i++] = ch;} while(ch!= 'n');str[i] = '';return i;}(d)int read_line(char str[], int n){ int ch, i;for(i = 0;i < n;i++){ ch = getchar();if(ch == 'n')break;str[i] = ch;} str[i] = '';return i;} 6.[was #6] void censor(char s[]){ int i;for(i = 0;s[i]!= '';i++)if(s[i] == 'f' && s[i+1] == 'o' && s[i+2] =='o')s[i] = s[i+1] = s[i+2] = 'x';} Note that the short-circuit evaluation of && prevents the if statement from testing characters that follow the null character.8.[was #10] tired-or-wired? 10.[was #12] The value of q is undefined, so the call of strcpy attempts to copy the string pointed to by p into some unknown area of memory.Exercise 2 in Chapter 17 discusses how to write this function correctly.15.[was #8](a)3(b)0(c)The length of the longest prefix of the string s that consists entirely of characters from the string t.Or, equivalently, the position of the first character in s that is not also in t.16.[was #16] int count_spaces(const char *s){ int count = 0;while(*s)if(*s++ == ' ')count++;return count;} Answers to Selected Programming Projects 1.[was #14] #include #include #define WORD_LEN 20void read_line(char str[], int n);int main(void){ char smallest_word[WORD_LEN+1], largest_word[WORD_LEN+1], current_word[WORD_LEN+1];printf(“Enter word: ”);read_line(current_word, WORD_LEN);strcpy(smallest_word, strcpy(largest_word, current_word));while(strlen(current_word)!= 4){ printf(“Enter word: ”);read_line(current_word, WORD_LEN);if(strcmp(current_word, smallest_word)< 0)strcpy(smallest_word, current_word);if(strcmp(current_word, largest_word)> 0)strcpy(largest_word, current_word);} printf(“nSmallest word: %sn”, smallest_word);printf(“Largest word:%sn”, largest_word);return 0;}void read_line(char str[], int n){ int ch, i = 0;while((ch = getchar())!= 'n')if(i < n)str[i++] = ch;str[i] = '';} 4.[was #18] #includeint main(int argc, char *argv[]){ int i;for(i = argc-1;i > 0;i--)printf(“%s ”, argv[i]);printf(“n”);return 0;} 6.[was #20] #include #include #include#define NUM_PLANETS 9int string_equal(const char *s, const char *t);int main(int argc, char *argv[]){ char *planets[] = {“Mercury”, “Venus”, “Earth”, “Mars”, “Jupiter”, “Saturn”, “Uranus”, “Neptune”, “Pluto”};int i, j;for(i = 1;i < argc;i++){ for(j = 0;j < NUM_PLANETS;j++)if(string_equal(argv[i],planets[j])){ printf(“%s is planet %dn”, argv[i], j + 1);break;} if(j == NUM_PLANETS)printf(“%s is not a planetn”, argv[i]);} return 0;}int string_equal(const char *s, const char *t){ int i;for(i = 0;toupper(s[i])== toupper(t[i]);i++)if(s[i] == '')return 1;return 0;}Chapter 14 Answers to Selected Exercises 2.[was #2] #define NELEMS(a)((int)(sizeof(a)/ sizeof(a[0])))4.[was #4](a)One problem stems from the lack of parentheses around the replacement list.For example, the statement a = 1/AVG(b, c);will be replaced by a = 1/(b+c)/2;Even if we add the missing parentheses, though, the macro still has problems, because it needs parentheses around x and y in the replacement list.The preprocessor will turn the statement a = AVG(bd);into a =((bd)/2);which is equivalent to a =((bd)/2);Here's the final(corrected)version of the macro: #define AVG(x,y)(((x)+(y))/2)(b)The problem is the lack of parentheses around the replacement list.For example, a = 1/AREA(b, c);becomes a = 1/(b)*(c);Here's the corrected macro: #define AREA(x,y)((x)*(y))5.[was #6](a)The call of putchar expands into the following statement: putchar(('a'<=(s[++i])&&(s[++i])<='z'?(s[++i])-'a'+'A':(s[++i])));The character a is less than or equal to s[1](which is b), yielding a true condition.The character s[2](which is c)is less than or equal to z, which is also true.The value printed is s[3]-'a'+'A', which is D(assuming that the character set is ASCII).(b)The character a is not less than or equal to s[1](which is 1)so the test condition is false.The value printed is s[2], which is 2.7.[was #8](a)long long_max(long x, long y){ return x > y ? x : y;} The preprocessor would actually put all the tokens on one line, but this version is more readable.(b)The problem with types such as unsigned long is that they require two words, which prevents GENERIC_MAX from creating the desired function name.For example, GENERIC_MAX(unsigned long)would expand intounsigned long unsigned long_max(unsigned long x, unsigned long y){ return x > y ? x : y;}(c)To make GENERIC_MAX work with any basic type, use a type definition to rename the type: typedef unsigned long ULONG;We can now write GENERIC_MAX(ULONG).12.[was #10](c)and(e)will fail, since M is defined.14.[was #12;modified] Here's what the program will look like after preprocessing: Blank line Blank line Blank line Blank line Blank line Blank line Blank lineint main(void){ int a[= 10], i, j, k, m;Blank line i = j;Blank line Blank line Blank linei = 10 * j+1;i =(x,y)x-y(j, k);i =((((j)*(j)))*(((j)*(j))));i =(((j)*(j))*(j));i = jk;puts(“i” “j”);Blank line i = SQR(j);Blank line i =(j);return 0;} Some preprocessors delete white-space characters at the beginning of a line, so your results may vary.Three lines will cause errors when the program is compiled.Two contain syntax errors: int a[= 10], i, j, k, m;i =(x,y)x-y(j, k);The third refers to an undefined variable: i = jk;Chapter 15 Answers to Selected Exercises 2.[was #2](b).Function definitions should not be put in a header file.If a function definition appears in a header file that is included by two(or more)source files, the program can't be linked, since the linker will see two copies of the function.6.[was #8](a)main.c, f1.c, and f2.c.(b)f1.c(assuming that f1.h is not affected by the change).(c)main.c, f1.c, and f2.c, since all three include f1.h.(d)f1.c and f2.c, since both include f2.h.Chapter 16 Answers to Selected Exercises 2.[was #2;modified](a)struct { double real, imaginary;} c1, c2, c3;(b)struct { double real, imaginary;} c1 = {0.0, 1.0}, c2 = {1.0, 0.0}, c3;(c)Only one statement is necessary: c1 = c2;(d)c3.real = c1.real + c2.real;c3.imaginary = c1.imaginary +c2.imaginary;4.[was #4;modified](a)typedef struct { double real, imaginary;} Complex;(b)Complex c1, c2, c3;(c)Complex make_complex(double real, double imaginary){ Complex c;c.real = real;c.imaginary = imaginary;return c;}(d)Complex add_complex(Complex c1, Complex c2){ Complex c3;c3.real = c1.real + c2.real;c3.imaginary = c1.imaginary + c2.imaginary;return c3;} 11.[was #10;modified] The a member will occupy 8 bytes, the union e will take 8 bytes(the largest member, c, is 8 bytes long), and the array f will require 4 bytes, so the total space allocated for s will be 20 bytes.14.[was #12;modified](a)double area(struct shape s){ if(s.shape_kind == RECTANGLE)return s.u.rectangle.height * s.u.rectangle.width;else return 3.14159 * s.u.circle.radius * s.u.circle.radius;}(b)struct shape move(struct shape s, int x, int y){ struct shape new_shape = s;new_shape.center.x += x;new_shape.center.y += y;return new_shape;}(c)struct shape scale(struct shape s, double c){ struct shape new_shape = s;if(new_shape.shape_kind == RECTANGLE){ new_shape.u.rectangle.height *= c;new_shape.u.rectangle.width *= c;} else new_shape.u.circle.radius *= c;return new_shape;} 15.[was #14](a)enum week_days {MON, TUE, WED, THU, FRI, SAT, SUN};(b)typedef enum {MON, TUE, WED, THU, FRI, SAT, SUN} Week_days;17.[was #16] All the statements are legal, since C allows integers and enumeration values to be mixed without restriction.Only(a),(d), and(e)are safe.(b)is not meaningful if i has a value other than 0 or 1.(c)will not yield a meaningful result if b has the value 1.Answers to Selected Programming Projects 1.[was #6;modified] #include#define COUNTRY_COUNT((int)(sizeof(country_codes)/sizeof(country_codes[0])))struct dialing_code { char *country;int code;};const struct dialing_code country_codes[] = {{“Argentina”, 54}, {“Bangladesh”, 880}, {“Brazil”, 55}, {“Burma(Myanmar)”, 95}, {“China”, 86}, {“Colombia”, 57}, {“Congo, Dem.Rep.of”, 243}, {“Egypt”, 20}, {“Ethiopia”, 251}, {“France”, 33}, {“Germany”, 49}, {“India”, 91}, {“Indonesia”, 62}, {“Iran”, 98}, {“Italy”, 39}, {“Japan”, 81}, {“Mexico”, 52}, {“Nigeria”, 234}, {“Pakistan”, 92}, {“Philippines”, 63}, {“Poland”, 48}, {“Russia”, 7}, {“South Africa”, 27}, {“South Korea”, 82}, {“Spain”, 34}, {“Sudan”, 249}, {“Thailand”, 66}, {“Turkey”, 90}, {“Ukraine”, 380}, {“United Kingdom”, 44}, {“United States”, 1}, {“Vietnam”, 84}};int main(void){ int code, i;printf(“Enter dialing code: ”);scanf(“%d”, &code);for(i = 0;i < COUNTRY_COUNT;i++)if(code == country_codes[i].code){ printf(“The country with dialing code %d is %sn”, code, country_codes[i].country);re turn 0;} printf(“No corresponding country foundn”);return 0;} 3.[was #8] #include #include “readline.h”#define NAME_LEN 25 #define MAX_PARTS 100struct part { int number;char name[NAME_LEN+1];int on_hand;};int find_part(int number, const struct part inv[], int np);void insert(struct part inv[], int *np);void search(const struct part inv[], int np);void update(struct part inv[], int np);void print(const struct part inv[], int np);/********************************************************** * main: Prompts the user to enter an operation code, * * then calls a function to perform the requested * * action.Repeats until theuser enters the * * command 'q'.Prints an error message if the user * * enters an illegal code.* **********************************************************/ int main(void){ char code;struct part inventory[MAX_PARTS];int num_parts = 0;for(;;){ printf(“Enter operation code: ”);scanf(“ %c”, &code);while(getchar()!= 'n')/* skips to end of line */;switch(code){ case 'i': insert(inventory, &num_parts);break;case 's': search(inventory, num_parts);break;case 'u': update(inventory, num_parts);break;case 'p': print(inventory, num_parts);break;case 'q': return 0;default: printf(“Illegal coden”);} printf(“n”);} } /********************************************************** * find_part: Looks up a part number in the inv array.* * Returns the array index if the part number * * is found;otherwise, returns-1.* **********************************************************/ int find_part(int number, const struct part inv[], int np){ int i;for(i = 0;i < np;i++)if(inv[i].number == number)return i;return-1;}/********************************************************** * insert: Prompts the user for information about a new * * part and then inserts the part into the inv * * array.Prints an error message and returns * * prematurely if the part already exists or the * * array is full.* **********************************************************/ void insert(struct part inv[], int *np){ int part_number;if(*np == MAX_P ARTS){ printf(“Database is full;can't add more parts.n”);return;}printf(“Enter part number: ”);scanf(“%d”, &part_number);if(find_part(part_number, inv, *np)>= 0){ printf(“Part already exists.n”);return;}inv[*np].number = part_number;printf(“Enter part na me: ”);read_line(inv[*np].name, NAME_LEN);printf(“Enter quantity on hand: ”);scanf(“%d”, &inv[*np].on_hand);(*np)++;} /********************************************************** * search: Prompts the user to enter a part number, then * * looks up the part in the inv array.If the * * part exists, prints the name and quantity on * * hand;if not, prints an error message.* **********************************************************/ void search(const struct part inv[], int np){ int i, number;printf(“Enter part number: ”);scanf(“%d”, &number);i = find_part(number, inv, np);if(i >= 0){ printf(“Part name: %sn”, inv[i].name);printf(“Quantity on hand: %dn”, inv[i].on_hand);} else printf(“Part not found.n”);}/********************************************************** * update: Prompts the user to enter a part number.* * Prints an error message if the part can't be * * found in the inv array;otherwise, prompts the * * user to enter change in quantity on hand and * * updates the array.* **********************************************************/ void update(struct part inv[], int np){ int i, number, change;printf(“Enter part number: ”);scanf(“%d”, &number);i = find_part(number, inv, np);if(i >= 0){ printf(“Enter change in quantity on hand: ”);scanf(“%d”, &change);inv[i].on_hand += change;} else printf(“Part not found.n”);}/********************************************************** * print: Prints a listing of all parts in the inv array, * * showing the part number, part name, and * * quantity on hand.Parts are printed in the * * order in which they were entered into the * * array.* **********************************************************/ void print(const struct part inv[], int np){ int i;printf(“Part Number Part Name ” “Quantity on Handn”);for(i = 0;i < np;i++)printf(“%7d %-25s%11dn”, inv[i].number, inv[i].name, inv[i].on_hand);}Chapter 17 Answers to Selected Exercises 2.[was #2;modified] char *duplicate(const char *s){ char *temp = malloc(strlen(s)+ 1);if(temp == NULL)return NULL;strcpy(temp, s);return temp;} 5.[was #6](b)and(c)are legal.(a)is illegal because it tries to reference a member of d without mentioning d.(d)is illegal because it uses-> instead of.to reference the c member of d.7.[was #8] The first call of free will release the space for the first node in the list, making p a dangling pointer.Executing p = p->next to advance to the next node will have an undefined effect.Here's a correct way to write the loop, using a temporary pointer that points to the node being deleted: struct node *temp;p = first;while(p!= NULL){ temp = p;p = p->next;free(temp);} 8.[was #10;modified] #include /* C99 only */ #include #include #include “stack.h”struct node { int value;struct node *next;};struct node *top = NULL;void make_empty(void){ struct node *temp;第二篇:《C语言程序设计教程(第二版)》习题答案《C语言程序设计教程(第二版)》习题答案说明1.本习题答案是我自己做的,错误和疏漏在所难免。

西工大noj答案完整版

西工大noj答案完整版

西北工业大学 POJ答案绝对是史上最全版(不止100题哦,,按首字母排序)1.“ 1“的传奇2.A+B3.A+BⅡ4.AB5.ACKERMAN6.Arithmetic Progressions7.Bee8.Checksum algorithm9.Coin Test10.Dexter need help11.Double12.Easy problem13.Favorite number14.Graveyard15.Hailstone16.HanoiⅡ17.Houseboat18.Music Composer19.Redistribute wealth20.Road trip21.Scoring22.Specialized Numbers23.Sticks24.Sum of Consecutive25.Symmetric Sort26.The Clock27.The Ratio of gainers to losers28.VOL 大学乒乓球比赛29.毕业设计论文打印30.边沿与内芯的差31.不会吧,又是 A+B32.不屈的小蜗33.操场训练34.插入链表节点35.插入排序36.插入字符37.成绩表计算38.成绩转换39.出租车费40.除法41.创建与遍历职工链表42.大数乘法43.大数除法44.大数加法45.单词频次46.迭代求根47.多项式的猜想48.二分查找49.二分求根50.发工资的日子51.方差52.分离单词53.分数拆分54.分数化小数55.分数加减法56.复数57.高低交换58.公园喷水器59.韩信点兵60.行程编码压缩算法61.合并字符串62.猴子分桃63.火车站64.获取指定二进制位65.积分计算66.级数和67.计算 A+B68.计算 PI69.计算π70.计算成绩71.计算完全数72.检测位图长宽73.检查图像文件格式74.奖金发放75.阶乘合计76.解不等式77.精确幂乘78.恐怖水母79.快速排序80.粒子裂变81.链表动态增长或缩短82.链表节点删除83.两个整数之间所有的素数84.路痴85.冒泡排序86.你会存钱吗87.逆序整数88.排列89.排列分析90.平均值函数91.奇特的分数数列92.求建筑高度93.区间内素数94.三点顺序95.山迪的麻烦96.删除字符97.是该年的第几天98.是该年的第几天?99.数据加密100.搜索字符101.所有素数102.探索合数世纪103.特殊要求的字符串104.特殊整数105.完全数106.王的对抗107.危险的组合108.文件比较109.文章统计110.五猴分桃111.小型数据库112.幸运儿113.幸运数字” 7“114.选择排序115.寻找规律116.循环移位117.延伸的卡片118.羊羊聚会119.一维数组”赋值“120.一维数组”加法“121.勇闯天涯122.右上角123.右下角124.圆及圆球等的相关计算125.圆及圆球等相关计算126.程序员添加行号127.找出数字128.找幸运数129.找最大数130.整数位数131.重组字符串132.子序列的和133.子字符串替换134.自然数立方的乐趣135.字符串比较136.字符串复制137.字符串加密编码138.字符串逆序139.字符串排序140.字符串替换141.字符串左中右142.组合数143.最次方数144.最大乘积145.最大整数146.最小整数147.最长回文子串148.左上角149.左下角1.“ 1“的传奇#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){int n,i,j,k=0,x=1,y,z,m,p,q,a,s=0;scanf("%d",&n);m=n;for(i=1;i<12;i++){m=m/10;k++;if(m==0)break;}q=n;k=k-1;for(a=1;a<=k;a++){x=x*10;}y=q%x;z=q/x;p=q-y;if(z>=2)s=s+x+z*k*(x/10); elses=s+z*k*(x/10); for(j=p;j<=n;j++){m=j;for(i=1;i<12;i++){x=m%10;if(x==1)s++;m=m/10;if(m==0)break;}}printf("%d",s);return 0;}2.A+B#include <stdio.h>int doubi(int n,int m){n=n+m;n=n%100;return n;}int main(){int t,i,a[100],n,m; scanf("%d",&t);for (i=0;i<=(t-1);i++){scanf("%d%d",&n,&m);a[i]=doubi(n,m);}for (i=0;i<=(t-1);i++)printf("%d\n",a[i]); return 0;}3.A+BⅡ#include <stdio.h>int main(){int A,B,sum;scanf("%d%d",&A,&B);sum=A+B;printf("%d\n",sum);return 0;}4.AB#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){char s[100],q[100];double a,b,c;int n=0,i;scanf("%lf%lf",&a,&b);c=a*b;sprintf(s,"%.0lf",c);for(i=0;i<strlen(s);i++){ n=n+s[i]-48;}while(n>=10){sprintf(q,"%d",n);n=0;for(i=0;i<strlen(q);i++)n=n+q[i]-48;}printf("%d",n);return 0;}5.ACKERMAN#include <stdio.h>#include <stdlib.h>int ack(int x,int y){int n;if (x==0) {n=y+1;return n;}else if (y==0) n=ack(x-1,1);else n=ack(x-1,ack(x,y-1));return n;}int main(){int m,b;scanf("%d%d",&m,&b);m=ack(m,b);printf("%d",m);return 0;}6.Arithmetic Progressions #include <stdio.h>#include <math.h>int g(int n){int i;if(n==1) return 0;if(n==2) return 1;if(n==3) return 1;for(i=2;i<=sqrt(n);i++) if(n%i==0) return 0;return 1;}int f(int a,int b,int c){int i=0,s=a-b;if(c==1&&g(a)==1) return a;if(b==0&&g(a)!=1) return -1;while(1){s=s+b;if(g(s)) i++;if(i>=c) break;}return s;int main(){int a,b,c,d[100],i=0,n;while(1){scanf("%d%d%d",&a,&b,&c);if(a==0&&b==0&&c==0) break;d[i]=f(a,b,c);i++;}n=i;for(i=0;i<n;i++)printf("%d\n",d[i]);return 0;}7.Bee#include <stdio.h>#include <stdlib.h>int main()int A[100],i=0,j,k,female=0,male=1,x;for(;;i++){scanf("%d",&A[i]);if(A[i]==-1)break;}for(j=0;j<i;j++){female=0,male=1;for(k=1;k<A[j];k++){x=female;female=male;male=x+male+1;}printf("%d %d\n",male,female+male+1);}return 0;}8.Checksum algorithm #include <stdio.h>#include <stdlib.h>#include <string.h>int main(){int i,n,t,j;char s[100][100];for(i=0;;i++){gets(s[i]);if(s[i][0]=='#') break;}n=i;for(i=0;i<n;i++){t=0;for(j=0;j<strlen(s[i]);j++)if(s[i][j]==32) t=t;else t=t+(j+1)*(s[i][j]-64);printf("%d\n",t);}return 0;}9.Coin Test#include <stdio.h>#include <stdlib.h>int main(){char A[100000];int n,i=0,a=0,b=0,j;double x;while(1){scanf("%c",&A[i]);if(A[i]=='\n')break;i++;}for(j=0;j<i;j++){if(A[j]=='S'){printf("WA");goto OH;}if(A[j]=='U')a++;if(A[j]=='D')b++;}x=a*1.0/(a+b)*1.0;if(x-0.5>0.003||x-0.5<-0.003) printf("Fail");elseprintf("%d/%d",a,a+b);OH:return 0;}10.Dexter need help#include <stdio.h>int fun(int a){if(a==1) return 1;elsereturn fun(a/2)+1; }int main(){int a,b[100],i=0,j; while(1){scanf("%d",&a);if(a==0)break;b[i]=fun(a);i++;}for(j=0;j<i;j++){printf("%d\n",b[j]); }return 0;}11.Double#include <stdio.h> #include <stdlib.h>int main(){int a[100],b[100],i,j,n,t=0;for(i=0;;i++){scanf("%d",&a[i]);if(a[i]==0) break;}n=i;for(i=0;i<n;i++)b[i]=2*a[i];for(i=0;i<n;i++)for(j=0;j<n;j++)if(a[i]==b[j]) t++;printf("%d",t);return 0;}12.Easy problem#include <stdio.h>#include <math.h>int main(){int N,i,n,j=0;scanf("%d",&N);for(i=2;i<N+1;i++){if((N+1)%i==0)j++;}printf("%d",j/2);return 0;}13.Favorite number #include <stdio.h>#include <string.h>#define MAXNUM 100000int prime_number = 0;int prime_list[MAXNUM]; bool is_prime[MAXNUM]; int ans[MAXNUM + 2];int dp[MAXNUM + 2];void set_prime() {int i, j;memset(is_prime, 0, sizeof(is_prime));for (i = 2; i < MAXNUM; i++) {if (is_prime[i] == 0) {prime_list[prime_number++] = i;if (i >= MAXNUM / i) continue;for (j = i * i; j < MAXNUM; j+=i) {is_prime[j] = 1;}}}}int main() {int i, j, k,o=0,d[100];memset(dp, -1, sizeof(dp));set_prime();ans[0] = 0;dp[1] = 0;for (i = 1; i <= MAXNUM; i++) {ans[i] = ans[i - 1] + dp[i];if (dp[i + 1] == -1 || dp[i + 1] > dp[i] + 1){dp[i + 1] = dp[i] + 1;}for (j = 0; j < prime_number; j++) {if (i > MAXNUM / prime_list[j]) break;k = i * prime_list[j];if (dp[k] == -1 || dp[k] > dp[i] + 1) {dp[k] = dp[i] + 1;}}}while (scanf("%d%d", &i, &j) == 2 && (i || j)) { d[o]=ans[j] - ans[i - 1];o++;}for(i=0;i<o;i++)printf("%d\n",d[i]);}14.Graveyard#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){int a[100],b[100],n,i,j;double s,p,l,t;for(i=0;;i++){scanf("%d%d",&a[i],&b[i]);if(a[i]==0&&b[i]==0) break;}n=i;for(i=0;i<n;i++){p=10000;if(b[i]%a[i]==0){printf("0.0000\n");continue;};t=10000/((double)a[i]);for(j=1;j<a[i]+b[i];j++){l=10000/((double)(a[i]+b[i]));l=t-j*l;l=fabs(l);if(l<p) p=l;}s=(a[i]-1)*p;printf("%.4lf\n",s);}return 0;}15.Hailstone#include <stdio.h>#include <stdlib.h>#include <string.h>int f(int n){int s=1;while(1){if(n==1) return s;else if(n%2==0) n=n/2,s++;else n=3*n+1,s++;}}int main(){int n,m,i,j=0,t;scanf("%d%d",&m,&n);printf("%d %d",m,n);if(m>n) t=m,m=n,n=t;for(i=m;i<=n;i++)if(f(i)>j) j=f(i);printf(" %d",j);return 0;}16.HanoiⅡ#include <stdio.h>#include <stdlib.h>#define M 70int start[M], targe[M];long long f(int *p, int k, int fina) {if(k==0) return 0;if(p[k]==fina) return f(p,k-1,fina);return f(p,k-1,6-fina-p[k])+(1LL<<(k-1));}int main (){long long ans;int n;while(scanf("%d",&n),n){int i;for(i=1;i<=n;i++) scanf("%d",&start[i]);for(i=1;i<=n;i++) scanf("%d",&targe[i]);int c=n;for(;c>=1&&start[c]==targe[c];c--);if(c==0){printf("0\n"); continue;}int other=6-start[c]-targe[c]; ans=f(start,c-1,other)+f(targe,c-1,other)+1;printf("%lld\n",ans);}return 0;}17.Houseboat#include <stdio.h>#include <stdlib.h>#include <math.h>#define pi 3.1415926int f(float x,float y){int i;for(i=0;;i++)if(50*i>sqrt(x*x+y*y)*sqrt(x*x+y*y)*pi/2) break;return i;}int main(){int n,i,a[100];float x,y;scanf("%d",&n);for(i=0;i<n;i++){scanf("%f%f",&x,&y);a[i]=f(x,y);}for(i=0;i<n;i++)printf("%d %d\n",i+1,a[i]);return 0;}18.Music Composer19.Redistribute wealth#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){inta[1000],b[1000],n,i,j,s,sum,t,m,mid,c[100],k=0;while(1){scanf("%d",&n);if(n==0) break;{s=0;for(i=1;i<=n;i++){scanf("%d",&a[i]);s=s+a[i];}m=s/n;b[1]=a[1]-m;b[0]=0;for(i=2;i<n;++i)b[i]=b[i-1]+a[i]-m;for(i=0;i<n;i++)for(j=0;j<n-1-i;j++)if(b[j]>b[j+1])t=b[j],b[j]=b[j+1],b[j+1]=t;mid=b[n/2];sum=0;for(i=0;i<=n-1;++i) sum=sum+fabs(mid-b[i]);c[k]=sum;k++;}}for(i=0;i<k;i++) printf("%d\n",c[i]);return 0;}20.Road trip#include <stdio.h>#include <stdlib.h>#include <math.h>int f(int n){int a[100],b[100],i,s;for(i=0;i<n;i++)scanf("%d%d",&a[i],&b[i]);s=a[0]*b[0];for(i=1;i<n;i++)s=s+a[i]*(b[i]-b[i-1]);return s;}int main(){int n,c[100],i=0;while(1){scanf("%d",&n);if(n==-1) break;c[i]=f(n);i++;}n=i;for(i=0;i<n;i++)printf("%d\n",c[i]);return 0;}21.Scoring#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){int i,j,sum,min,c,count,n,a,b; char s1[50],s2[50];scanf("%d",&n);for(i=0;i<n;i++){count=sum=0;scanf("%s",s2);for(j=0;j<4;j++){scanf("%d%d",&a,&b);if(b!=0){sum+=(a-1)*20+b;count++;}}if(i==0){c=count,min=sum;strcpy(s1,s2);}else if(count>c||(count==c&&sum<min)) {min=sum;c=count;strcpy(s1,s2);}}printf("%s %d %d\n",s1,c,min); return 0;}22.Specialized Numbers#include <stdio.h>#include <stdlib.h>int main(){int i,n,sum10,sum12,sum16;for(i=2992;i<3000;i++){n=i;sum10=0;while(n){sum10+=n%10;n/=10;}n=i;sum12=0;while(n){sum12+=n%12;n/=12;}n=i;sum16=0;while(n){sum16+=n%16;n/=16;}if(sum10==sum12&&sum12==sum16) printf("%d\n",i);}return 0;}23.Sticks#include <stdio.h>#include <string.h>#include <stdlib.h>int len[64], n, minlen, get;bool b[64];int cmp(const void *a, const void *b){return *(int *)a < *(int *)b ? 1 : -1;}bool dfs(int nowlen, int nowget, int cnt) {if(cnt >= n) return false;if(get == nowget) return true;int i;bool f = false;if(nowlen == 0) f = true;for(i = cnt; i < n; i++){if(!b[i]){if(len[i] + nowlen == minlen){b[i] = true;if(dfs(0, nowget+1, nowget))return true;b[i] = false;return false;}else if(len[i] + nowlen < minlen){b[i] = true;if(dfs(nowlen+len[i], nowget, i+1))return true;b[i] = false;if(f) return false;while(i+ 1 < n && len[i]== len[i+1]) i++;}}}return false;}int main(){int i, tollen;while(scanf("%d", &n), n){tollen = 0;int j = 0, p;for(i = 0; i < n; i++){scanf("%d", &p);if(p <= 50){len[j] = p;tollen += len[j];j++;}}n = j;if(n == 0){printf("0\n");continue;}qsort(len, n, sizeof(int), cmp);for(minlen = len[0]; ; minlen++){if(tollen % minlen) continue;memset(b, 0, sizeof(b));get = tollen / minlen;if(dfs(0, 0, 0)){printf("%d\n", minlen);break;}}}return 0;}24.Sum of Consecutive#include <stdio.h>#include <stdlib.h>#include <string.h>int len[64],n,minlen,get;int b[64];int cmp(const void *a,const void *b) {return *(int *)a<*(int *)b?1:-1;}int dfs(int nowlen,int nowget,int cnt){if(cnt>=n) return 0;if(get==nowget) return 1;int i,f=0;if(nowlen==0) f=1;for(i=cnt;i<n;i++){if(len[i]+nowlen==minlen){b[i]=1;if(dfs(0,nowget+1,nowget)) return 1;b[i]=0;return 0;}else if(len[i]+nowlen<minlen){b[i]=1;if(dfs(nowlen+len[i],nowget,i+1)) return 1;b[i]=0;if(f) return 0;while(i+1<n&&len[i]==len[i+1]) i++;}}return 0;}int main(){int i,tollen,q=0,c[100];while(scanf("%d",&n),n){tollen=0;int j=0,p;for(i=0;i<n;i++){scanf("%d",&p);if(p<=50){len[j]=p;tollen+=len[j];j++;}}n=j;if(n==0){printf("0\n");continue;}qsort(len,n,sizeof(int),cmp);for(minlen=len[0];;minlen++){if(tollen%minlen) continue;memset(b,0,sizeof(b));get=tollen/minlen;if(dfs(0,0,0)){c[q]=minlen;q++;break;}}}for(i=0;i<q;i++)printf("%d\n",c[i]);return 0;}25.Symmetric Sort#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){double A[100];int i=0,j=0,k=0,l=0,sum=0;while(1){scanf("%lf",&A[i]);if(A[i]==0)break;i++;}for(j=0;j<i;j++){if(A[j]==2)printf("1\n");else{int B[10000],m=1,number=0;double n;B[0]=2;for(k=3;k<=A[j];k+=2){n=(double)k;for(l=2;l<=sqrt(n);l++){if(k%l==0)goto ai;}B[m]=k;m++;ai:;}for(k=0;k<m;k++){sum=0;for(l=k;l<m;l++){sum+=B[l];if(sum==A[j]){number++;break;}}}printf("%d\n",number);}}return 0;}26.The Clock#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){char s[100][100],a[100];int i,j,n;scanf("%d",&n);for(i=0;i<n;i++) scanf("%s",s[i]);for(i=0;i<n-1;i++)for(j=0;j<n-1-i;j++)if(strlen(s[i])>strlen(s[i+1]))strcpy(a,s[i]),strcpy(s[i],s[i+1]),strcpy(s[i+1],a) ;if(n%2==0){for(i=0;i<n-1;i=i+2) printf("%s ",s[i]);printf("%s ",s[n-1]);for(i=i-3;i>0;i=i-2) printf("%s ",s[i]);}else{for(i=0;i<n-1;i=i+2) printf("%s ",s[i]);printf("%s ",s[n-1]);for(i=i-1;i>0;i=i-2) printf("%s ",s[i]);}return 0;}27.The Ratio of gainers to losers #include<stdio.h>int main(){char s[5];int i,sum=0;gets(s);for(i=0;s[i]!='\0';i++){switch(s[i]){case'I': sum+=1;break; case'V': sum=5-sum;break; case'X':sum=10-sum;break; }}printf("%d\n",sum);return 0;}28.VOL大学乒乓球比赛#include <stdio.h>#include <stdlib.h>int main(){printf("A=Z\nB=X\nC=Y\n");return 0;}29.毕业设计论文打印#include <stdio.h>#include <stdlib.h>int main(){int a[100],j=1,i,n,m;scanf("%d%d",&n,&m);for(i=0;i<n;i++)scanf("%d",&a[i]);for(i=0;i<n;i++)if(a[i]>a[m]) j++;printf("%d",j++);return 0;}30.边沿与内芯的差#include <stdio.h>#include <stdlib.h>int main(){int A[100][100],i,j,m,n,s=0,t=0;scanf("%d%d",&n,&m);for(i=1;i<=n;i++){for(j=1;j<=m;j++){scanf("%d",&A[i][j]);。

西工大noj标准答案版.doc

西工大noj标准答案版.doc

西北工业大学 POJ答案绝对是史上最全版(不止100哦⋯⋯按首字母排序)1.“ 1“的传奇2.A+B3.A+BⅡ4.AB5.ACKERMAN6.Arithmetic Progressions7.Bee8.Checksum algorithm9.Coin Test10.Dexter need help11.Double12.Easy problem13.Favorite number14.Graveyard15.Hailstone16.HanoiⅡ17.Houseboat18.Music Composer19.Redistribute wealth20.Road trip21.Scoring22.Specialized Numbers23.Sticks24.Sum of Consecutive25.Symmetric Sort26.The Clock27.The Ratio of gainers to losers28.VOL 大学乒乓球比赛29.毕业设计论文打印30.边沿与内芯的差31.不会吧,又是 A+B32.不屈的小蜗33.操场训练34.插入链表节点35.插入排序36.插入字符37.成绩表计算38.成绩转换39.出租车费40.除法41.创建与遍历职工链表42.大数乘法43.大数除法44.大数加法45.单词频次46.迭代求根47.多项式的猜想48.二分查找49.二分求根50.发工资的日子51.方差52.分离单词53.分数拆分54.分数化小数55.分数加减法56.复数57.高低交换58.公园喷水器59.韩信点兵60.行程编码压缩算法61.合并字符串62.猴子分桃63.火车站64.获取指定二进制位65.积分计算66.级数和67.计算 A+B68.计算 PI69.计算π70.计算成绩71.计算完全数72.检测位图长宽73.检查图像文件格式74.奖金发放75.阶乘合计76.解不等式77.精确幂乘78.恐怖水母79.快速排序80.粒子裂变81.链表动态增长或缩短82.链表节点删除83.两个整数之间所有的素数84.路痴85.冒泡排序86.你会存钱吗87.逆序整数88.排列89.排列分析90.平均值函数91.奇特的分数数列92.求建筑高度93.区间内素数94.三点顺序95.山迪的麻烦96.删除字符97.是该年的第几天98.是该年的第几天99.数据加密100.搜索字符101.所有素数102.探索合数世纪103.特殊要求的字符串104.特殊整数105.完全数106.王的对抗107.危险的组合108.文件比较109.文章统计110.五猴分桃111.小型数据库112.幸运儿113.幸运数字” 7“114.选择排序115.寻找规律116.循环移位117.延伸的卡片118.羊羊聚会119.一维数组”赋值“120.一维数组”加法“121.勇闯天涯122.右上角123.右下角124.圆及圆球等的相关计算125.圆及圆球等相关计算126.程序员添加行号127.找出数字128.找幸运数129.找最大数130.整数位数131.重组字符串132.子序列的和133.子字符串替换134.自然数立方的乐趣135.字符串比较136.字符串复制137.字符串加密编码138.字符串逆序139.字符串排序140.字符串替换141.字符串左中右142.组合数143.最次方数144.最大乘积145.最大整数146.最小整数147.最长回文子串148.左上角149.左下角1.“ 1“的传奇#include <>#include <>#include <>int main(){int n,i,j,k=0,x=1,y,z,m,p,q,a,s=0;scanf("%d",&n);m=n;for(i=1;i<12;i++){m=m/10;k++;if(m==0)break;}q=n;k=k-1;for(a=1;a<=k;a++){x=x*10;}y=q%x;z=q/x;p=q-y;if(z>=2)s=s+x+z*k*(x/10); elses=s+z*k*(x/10); for(j=p;j<=n;j++) {m=j;for(i=1;i<12;i++){x=m%10;if(x==1)s++;m=m/10;if(m==0)break;}}printf("%d",s);return 0;}2.A+B#include <>int doubi(int n,int m) {n=n+m;n=n%100;return n;}int main(){int t,i,a[100],n,m; scanf("%d",&t);for (i=0;i<=(t-1);i++){scanf("%d%d",&n,&m);a[i]=doubi(n,m);}for (i=0;i<=(t-1);i++)printf("%d\n",a[i]); return 0;}3.A+BⅡ#include <>int main(){int A,B,sum;scanf("%d%d",&A,&B);sum=A+B;printf("%d\n",sum);return 0;}4.AB#include <>#include <>#include <>int main(){char s[100],q[100];double a,b,c;int n=0,i;scanf("%lf%lf",&a,&b);c=a*b;sprintf(s,"%.0lf",c);for(i=0;i<strlen(s);i++){n=n+s[i]-48;}while(n>=10){sprintf(q,"%d",n);n=0;for(i=0;i<strlen(q);i++)n=n+q[i]-48;}printf("%d",n);return 0;}5.ACKERMAN#include <>#include <>int ack(int x,int y){int n;if (x==0) {n=y+1;return n;}else if (y==0) n=ack(x-1,1);else n=ack(x-1,ack(x,y-1));return n;}int main(){int m,b;scanf("%d%d",&m,&b);m=ack(m,b);printf("%d",m);return 0;}6.Arithmetic Progressions #include <>#include <>int g(int n){int i;if(n==1) return 0;if(n==2) return 1;if(n==3) return 1;for(i=2;i<=sqrt(n);i++) if(n%i==0) return 0;return 1;}int f(int a,int b,int c){int i=0,s=a-b;if(c==1&&g(a)==1) return a;if(b==0&&g(a)!=1) return -1;while(1){s=s+b;if(g(s)) i++;if(i>=c) break;}return s;int main(){int a,b,c,d[100],i=0,n;while(1){scanf("%d%d%d",&a,&b,&c);if(a==0&&b==0&&c==0) break;d[i]=f(a,b,c);i++;}n=i;for(i=0;i<n;i++)printf("%d\n",d[i]);return 0;}7.Bee#include <>#include <>int main()int A[100],i=0,j,k,female=0,male=1,x;for(;;i++){scanf("%d",&A[i]);if(A[i]==-1)break;}for(j=0;j<i;j++){female=0,male=1;for(k=1;k<A[j];k++){x=female;female=male;male=x+male+1;}printf("%d %d\n",male,female+male+1);}return 0;}8.Checksum algorithm #include <>#include <>#include <>int main(){int i,n,t,j;char s[100][100];for(i=0;;i++){gets(s[i]);if(s[i][0]=='#') break;}n=i;for(i=0;i<n;i++){t=0;for(j=0;j<strlen(s[i]);j++)if(s[i][j]==32) t=t;else t=t+(j+1)*(s[i][j]-64);printf("%d\n",t);}return 0;}9.Coin Test#include <>#include <>int main(){char A[100000];int n,i=0,a=0,b=0,j;double x;while(1){scanf("%c",&A[i]);if(A[i]=='\n')break;i++;}for(j=0;j<i;j++){if(A[j]=='S'){printf("WA");goto OH;}if(A[j]=='U')a++;if(A[j]=='D')b++;}x=a*(a+b)*;if>||<printf("Fail");elseprintf("%d/%d",a,a+b);OH:return 0;}10.Dexter need help #include <>int fun(int a){if(a==1) return 1;elsereturn fun(a/2)+1; }int main(){int a,b[100],i=0,j; while(1){scanf("%d",&a);if(a==0)break;b[i]=fun(a);i++;}for(j=0;j<i;j++){ printf("%d\n",b[j]); }return 0;}11.Double#include <>#include <>int main(){int a[100],b[100],i,j,n,t=0;for(i=0;;i++){scanf("%d",&a[i]);if(a[i]==0) break;}n=i;for(i=0;i<n;i++)b[i]=2*a[i];for(i=0;i<n;i++)for(j=0;j<n;j++)if(a[i]==b[j]) t++;printf("%d",t);return 0;}12.Easy problem#include <>#include <>int main(){int N,i,n,j=0;scanf("%d",&N);for(i=2;i<N+1;i++){if((N+1)%i==0)j++;}printf("%d",j/2);return 0;}13.Favorite number #include <>#include <>#define MAXNUM 100000int prime_number = 0;int prime_list[MAXNUM]; bool is_prime[MAXNUM]; int ans[MAXNUM + 2];int dp[MAXNUM + 2];void set_prime() {int i, j;memset(is_prime, 0, sizeof(is_prime));for (i = 2; i < MAXNUM; i++) {if (is_prime[i] == 0) {prime_list[prime_number++] = i;if (i >= MAXNUM / i) continue;for (j = i * i; j < MAXNUM; j+=i) {is_prime[j] = 1;}}}}int main() {int i, j, k,o=0,d[100];memset(dp, -1, sizeof(dp));set_prime();ans[0] = 0;dp[1] = 0;for (i = 1; i <= MAXNUM; i++) {ans[i] = ans[i - 1] + dp[i];if (dp[i + 1] == -1 || dp[i + 1] > dp[i] + 1) {dp[i + 1] = dp[i] + 1;}for (j = 0; j < prime_number; j++) {if (i > MAXNUM / prime_list[j]) break;k = i * prime_list[j];if (dp[k] == -1 || dp[k] > dp[i] + 1) {dp[k] = dp[i] + 1;}}}while (scanf("%d%d", &i, &j) == 2 && (i || j)){ d[o]=ans[j] - ans[i - 1];o++;}for(i=0;i<o;i++)printf("%d\n",d[i]);}14.Graveyard#include <>#include <>#include <>int main(){int a[100],b[100],n,i,j;double s,p,l,t;for(i=0;;i++){scanf("%d%d",&a[i],&b[i]);if(a[i]==0&&b[i]==0) break;}n=i;for(i=0;i<n;i++){p=10000;if(b[i]%a[i]==0){printf("\n");continue;};t=10000/((double)a[i]);for(j=1;j<a[i]+b[i];j++){l=10000/((double)(a[i]+b[i]));l=t-j*l;l=fabs(l);if(l<p) p=l;}s=(a[i]-1)*p;printf("%.4lf\n",s);}return 0;}15.Hailstone#include <>#include <>#include <>int f(int n){int s=1;while(1){if(n==1) return s;else if(n%2==0) n=n/2,s++;else n=3*n+1,s++;}}int main(){int n,m,i,j=0,t;scanf("%d%d",&m,&n);printf("%d %d",m,n);if(m>n) t=m,m=n,n=t;for(i=m;i<=n;i++)if(f(i)>j) j=f(i);printf(" %d",j);return 0;}16.HanoiⅡ#include <>#include <>#define M 70int start[M], targe[M];long long f(int *p, int k, int fina) {if(k==0) return 0;if(p[k]==fina) return f(p,k-1,fina);return f(p,k-1,6-fina-p[k])+(1LL<<(k-1));}int main (){long long ans;int n;while(scanf("%d",&n),n){int i;for(i=1;i<=n;i++) scanf("%d",&start[i]);for(i=1;i<=n;i++) scanf("%d",&targe[i]);int c=n;for(;c>=1&&start[c]==targe[c];c--);if(c==0){printf("0\n"); continue;}int other=6-start[c]-targe[c]; ans=f(start,c-1,other)+f(targe,c-1,other)+1;printf("%lld\n",ans);}return 0;}17.Houseboat#include <>#include <>#include <>#define piint f(float x,float y){int i;for(i=0;;i++)if(50*i>sqrt(x*x+y*y)*sqrt(x*x+y*y)*pi/2) break;return i;}int main(){int n,i,a[100];float x,y;scanf("%d",&n);for(i=0;i<n;i++){scanf("%f%f",&x,&y);a[i]=f(x,y);}for(i=0;i<n;i++)printf("%d %d\n",i+1,a[i]);return 0;}18.Music Composer19.Redistribute wealth#include <>#include <>#include <>int main(){inta[1000],b[1000],n,i,j,s,sum,t,m,mid,c[100],k=0;while(1){scanf("%d",&n);if(n==0) break;{s=0;for(i=1;i<=n;i++){scanf("%d",&a[i]);s=s+a[i];}m=s/n;b[1]=a[1]-m;b[0]=0;for(i=2;i<n;++i)b[i]=b[i-1]+a[i]-m;for(i=0;i<n;i++)for(j=0;j<n-1-i;j++)if(b[j]>b[j+1])t=b[j],b[j]=b[j+1],b[j+1]=t;mid=b[n/2];sum=0;for(i=0;i<=n-1;++i) sum=sum+fabs(mid-b[i]);c[k]=sum;k++;}}for(i=0;i<k;i++) printf("%d\n",c[i]);return 0;}20.Road trip#include <>#include <>#include <>int f(int n){int a[100],b[100],i,s;for(i=0;i<n;i++)scanf("%d%d",&a[i],&b[i]);s=a[0]*b[0];for(i=1;i<n;i++)s=s+a[i]*(b[i]-b[i-1]);return s;}int main(){int n,c[100],i=0;while(1){scanf("%d",&n);if(n==-1) break;c[i]=f(n);i++;}n=i;for(i=0;i<n;i++)printf("%d\n",c[i]);return 0;}21.Scoring#include <>#include <>#include <>int main(){int i,j,sum,min,c,count,n,a,b; char s1[50],s2[50];scanf("%d",&n);for(i=0;i<n;i++){count=sum=0;scanf("%s",s2);for(j=0;j<4;j++){scanf("%d%d",&a,&b);if(b!=0){sum+=(a-1)*20+b;count++;}}if(i==0){c=count,min=sum;strcpy(s1,s2);}else if(count>c||(count==c&&sum<min)) {min=sum;c=count;strcpy(s1,s2);}}printf("%s %d %d\n",s1,c,min); return 0;}22.Specialized Numbers#include <>#include <>int main(){int i,n,sum10,sum12,sum16;for(i=2992;i<3000;i++){n=i;sum10=0;while(n){sum10+=n%10;n/=10;}n=i;sum12=0;while(n){sum12+=n%12;n/=12;}n=i;sum16=0;while(n){sum16+=n%16;n/=16;}if(sum10==sum12&&sum12==sum16) printf("%d\n",i);}return 0;}23.Sticks#include <>#include <>#include <>int len[64], n, minlen, get;bool b[64];int cmp(const void *a, const void *b) {return *(int *)a < *(int *)b 1 : -1;}bool dfs(int nowlen, int nowget, int cnt) {if(cnt >= n) return false;if(get == nowget) return true;int i;bool f = false;if(nowlen == 0) f = true;for(i = cnt; i < n; i++){if(!b[i]){if(len[i] + nowlen == minlen){b[i] = true;if(dfs(0, nowget+1, nowget))return true;b[i] = false;return false;}else if(len[i] + nowlen < minlen){b[i] = true;if(dfs(nowlen+len[i], nowget, i+1))return true;b[i] = false;if(f) return false;while(i+ 1 < n && len[i] == len[i+1]) i++;}}}return false;}int main(){int i, tollen;while(scanf("%d", &n), n){tollen = 0;int j = 0, p;for(i = 0; i < n; i++){scanf("%d", &p);if(p <= 50){len[j] = p;tollen += len[j];j++;}}n = j;if(n == 0){printf("0\n");continue;}qsort(len, n, sizeof(int), cmp); for(minlen = len[0]; ; minlen++) {if(tollen % minlen) continue;memset(b, 0, sizeof(b));get = tollen / minlen;if(dfs(0, 0, 0)){printf("%d\n", minlen);break;}}}return 0;}24.Sum of Consecutive#include <>#include <>#include <>int len[64],n,minlen,get;int b[64];int cmp(const void *a,const void *b) {return *(int *)a<*(int *)b1:-1;}int dfs(int nowlen,int nowget,int cnt){if(cnt>=n) return 0;if(get==nowget) return 1;int i,f=0;if(nowlen==0) f=1;for(i=cnt;i<n;i++){if(len[i]+nowlen==minlen){b[i]=1;if(dfs(0,nowget+1,nowget)) return 1;b[i]=0;return 0;}else if(len[i]+nowlen<minlen){b[i]=1;if(dfs(nowlen+len[i],nowget,i+1)) return 1;b[i]=0;if(f) return 0;while(i+1<n&&len[i]==len[i+1]) i++;}}return 0;}int main(){int i,tollen,q=0,c[100];while(scanf("%d",&n),n){tollen=0;int j=0,p;for(i=0;i<n;i++){scanf("%d",&p);if(p<=50){len[j]=p;tollen+=len[j];j++;}}n=j;if(n==0){printf("0\n");continue;}qsort(len,n,sizeof(int),cmp);for(minlen=len[0];;minlen++){if(tollen%minlen) continue;memset(b,0,sizeof(b));get=tollen/minlen;if(dfs(0,0,0)){c[q]=minlen;q++;break;}}}for(i=0;i<q;i++)printf("%d\n",c[i]);return 0;}25.Symmetric Sort#include <>#include <>#include <>int main(){double A[100];int i=0,j=0,k=0,l=0,sum=0;while(1){scanf("%lf",&A[i]);if(A[i]==0)break;i++;}for(j=0;j<i;j++){if(A[j]==2)printf("1\n");else{int B[10000],m=1,number=0;double n;B[0]=2;for(k=3;k<=A[j];k+=2){n=(double)k;for(l=2;l<=sqrt(n);l++){if(k%l==0)goto ai;}B[m]=k;m++;ai:;}for(k=0;k<m;k++){sum=0;for(l=k;l<m;l++){sum+=B[l];if(sum==A[j]){number++;break;}}}printf("%d\n",number);}}return 0;}26.The Clock#include <>#include <>#include <>int main(){char s[100][100],a[100];int i,j,n;scanf("%d",&n);for(i=0;i<n;i++) scanf("%s",s[i]);for(i=0;i<n-1;i++)for(j=0;j<n-1-i;j++)if(strlen(s[i])>strlen(s[i+1]))strcpy(a,s[i]),strcpy(s[i],s[i+1]),strcpy(s[i+1],a) ;if(n%2==0){for(i=0;i<n-1;i=i+2) printf("%s ",s[i]);printf("%s ",s[n-1]);for(i=i-3;i>0;i=i-2) printf("%s ",s[i]);}else{for(i=0;i<n-1;i=i+2) printf("%s ",s[i]);printf("%s ",s[n-1]);for(i=i-1;i>0;i=i-2) printf("%s ",s[i]);}return 0;}27.The Ratio of gainers to losers #include<>int main(){char s[5];int i,sum=0;gets(s);for(i=0;s[i]!='\0';i++){switch(s[i]){case'I': sum+=1;break; case'V': sum=5-sum;break; case'X':sum=10-sum;break; }}printf("%d\n",sum);return 0;}28.VOL大学乒乓球比赛#include <>#include <>int main(){printf("A=Z\nB=X\nC=Y\n");return 0;}29.毕业设计论文打印#include <>#include <>int main(){int a[100],j=1,i,n,m;scanf("%d%d",&n,&m);for(i=0;i<n;i++)scanf("%d",&a[i]);for(i=0;i<n;i++)if(a[i]>a[m]) j++;printf("%d",j++);return 0;}30.边沿与内芯的差#include <>#include <>int main(){int A[100][100],i,j,m,n,s=0,t=0;scanf("%d%d",&n,&m);for(i=1;i<=n;i++){for(j=1;j<=m;j++){scanf("%d",&A[i][j]);}。

西工大noj问题详解解析汇报(完整版)

西工大noj问题详解解析汇报(完整版)

西北工业大学POJ答案绝对是史上最全版(不止100题哦……按首字母排序)1.“1“的传奇2.A+B3.A+BⅡ4.AB5.ACKERMAN6.Arithmetic Progressions7.Bee8.Checksum algorithm9.Coin Test10.Dexter need help11.Double12.Easy problem13.Favorite number14.Graveyard15.Hailstone16.Hanoi Ⅱ17.Houseboat18.Music Composer19.Redistribute wealth20.Road trip21.Scoring22.Specialized Numbers23.Sticks24.Sum of Consecutive25.Symmetric Sort26.The Clock27.The Ratio of gainers to losers28.VOL大学乒乓球比赛29.毕业设计论文打印30.边沿与内芯的差31.不会吧,又是A+B32.不屈的小蜗33.操场训练34.插入链表节点35.插入排序36.插入字符37.成绩表计算38.成绩转换39.出租车费40.除法41.创建与遍历职工链表42.大数乘法43.大数除法44.大数加法45.单词频次46.迭代求根47.多项式的猜想48.二分查找49.二分求根50.发工资的日子51.方差52.分离单词53.分数拆分54.分数化小数55.分数加减法56.复数57.高低交换58.公园喷水器59.韩信点兵60.行程编码压缩算法61.合并字符串62.猴子分桃63.火车站64.获取指定二进制位65.积分计算66.级数和67.计算A+B68.计算PI69.计算π70.计算成绩71.计算完全数72.检测位图长宽73.检查图像文件格式74.奖金发放75.阶乘合计76.解不等式77.精确幂乘78.恐怖水母79.快速排序80.粒子裂变81.链表动态增长或缩短82.链表节点删除83.两个整数之间所有的素数84.路痴85.冒泡排序86.你会存钱吗87.逆序整数88.排列89.排列分析90.平均值函数91.奇特的分数数列92.求建筑高度93.区间内素数94.三点顺序95.山迪的麻烦96.删除字符97.是该年的第几天98.是该年的第几天?99.数据加密100.搜索字符101.所有素数102.探索合数世纪103.特殊要求的字符串104.特殊整数105.完全数106.王的对抗107.危险的组合108.文件比较109.文章统计110.五猴分桃111.小型数据库112.幸运儿113.幸运数字”7“114.选择排序115.寻找规律116.循环移位117.延伸的卡片118.羊羊聚会119.一维数组”赋值“120.一维数组”加法“121.勇闯天涯122.右上角123.右下角124.圆及圆球等的相关计算125.圆及圆球等相关计算126.程序员添加行号127.找出数字128.找幸运数129.找最大数130.整数位数131.重组字符串132.子序列的和133.子字符串替换134.自然数立方的乐趣135.字符串比较136.字符串复制137.字符串加密编码138.字符串逆序139.字符串排序140.字符串替换141.字符串左中右142.组合数143.最次方数144.最大乘积145.最大整数146.最小整数147.最长回文子串148.左上角149.左下角1.“1“的传奇#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){int n,i,j,k=0,x=1,y,z,m,p,q,a,s=0;scanf("%d",&n);m=n;for(i=1;i<12;i++){m=m/10;k++;if(m==0)break;}q=n;k=k-1;for(a=1;a<=k;a++){x=x*10;}y=q%x;z=q/x;p=q-y;if(z>=2)s=s+x+z*k*(x/10); elses=s+z*k*(x/10); for(j=p;j<=n;j++) {m=j;for(i=1;i<12;i++){x=m%10;if(x==1)s++;m=m/10;if(m==0)break;}}printf("%d",s);return 0;}2.A+B#include <stdio.h>int doubi(int n,int m){n=n+m;n=n%100;return n;}int main(){int t,i,a[100],n,m;scanf("%d",&t);for (i=0;i<=(t-1);i++){scanf("%d%d",&n,&m);a[i]=doubi(n,m);}for (i=0;i<=(t-1);i++)printf("%d\n",a[i]);return 0;}3.A+BⅡ#include <stdio.h>int main(){int A,B,sum;scanf("%d%d",&A,&B);sum=A+B;printf("%d\n",sum);return 0;}4.AB#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){char s[100],q[100];double a,b,c;int n=0,i;scanf("%lf%lf",&a,&b);c=a*b;sprintf(s,"%.0lf",c);for(i=0;i<strlen(s);i++){n=n+s[i]-48;}while(n>=10){sprintf(q,"%d",n);n=0;for(i=0;i<strlen(q);i++)n=n+q[i]-48;}printf("%d",n);return 0;}5.ACKERMAN#include <stdio.h>#include <stdlib.h>int ack(int x,int y){int n;if (x==0) {n=y+1;return n;}else if (y==0) n=ack(x-1,1);else n=ack(x-1,ack(x,y-1));return n;}int main(){int m,b;scanf("%d%d",&m,&b);m=ack(m,b);printf("%d",m);return 0;}6.Arithmetic Progressions#include <stdio.h>#include <math.h>int g(int n){int i;if(n==1) return 0;if(n==2) return 1;if(n==3) return 1;for(i=2;i<=sqrt(n);i++) if(n%i==0) return 0;return 1;}int f(int a,int b,int c){int i=0,s=a-b;if(c==1&&g(a)==1) return a;if(b==0&&g(a)!=1) return -1;while(1){s=s+b;if(g(s)) i++;if(i>=c) break;}return s;int main(){int a,b,c,d[100],i=0,n;while(1){scanf("%d%d%d",&a,&b,&c);if(a==0&&b==0&&c==0) break;d[i]=f(a,b,c);i++;}n=i;for(i=0;i<n;i++)printf("%d\n",d[i]);return 0;}7.Bee#include <stdio.h>#include <stdlib.h>int main()int A[100],i=0,j,k,female=0,male=1,x;for(;;i++){scanf("%d",&A[i]);if(A[i]==-1)break;}for(j=0;j<i;j++){female=0,male=1;for(k=1;k<A[j];k++){x=female;female=male;male=x+male+1;}printf("%d %d\n",male,female+male+1);}return 0;}8.Checksum algorithm#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){int i,n,t,j;char s[100][100];for(i=0;;i++){gets(s[i]);if(s[i][0]=='#') break;}n=i;for(i=0;i<n;i++){t=0;for(j=0;j<strlen(s[i]);j++)if(s[i][j]==32) t=t;else t=t+(j+1)*(s[i][j]-64);printf("%d\n",t);}return 0;}9.Coin Test#include <stdio.h>#include <stdlib.h>int main(){char A[100000];int n,i=0,a=0,b=0,j;double x;while(1){scanf("%c",&A[i]);if(A[i]=='\n')break;i++;}for(j=0;j<i;j++){if(A[j]=='S'){printf("WA");goto OH;}if(A[j]=='U')a++;if(A[j]=='D')b++;}x=a*1.0/(a+b)*1.0;if(x-0.5>0.003||x-0.5<-0.003) printf("Fail");elseprintf("%d/%d",a,a+b);OH:return 0;}10.Dexter need help#include <stdio.h>int fun(int a){if(a==1) return 1;elsereturn fun(a/2)+1;}int main(){int a,b[100],i=0,j; while(1){scanf("%d",&a);if(a==0)break;b[i]=fun(a);i++;}for(j=0;j<i;j++){printf("%d\n",b[j]); }return 0;}11.Double#include <stdio.h>#include <stdlib.h>int main(){int a[100],b[100],i,j,n,t=0;for(i=0;;i++){scanf("%d",&a[i]);if(a[i]==0) break;}n=i;for(i=0;i<n;i++)b[i]=2*a[i];for(i=0;i<n;i++)for(j=0;j<n;j++)if(a[i]==b[j]) t++;printf("%d",t);return 0;}12.Easy problem#include <stdio.h>#include <math.h>int main(){int N,i,n,j=0;scanf("%d",&N);for(i=2;i<N+1;i++){if((N+1)%i==0)j++;}printf("%d",j/2);return 0;}13.Favorite number #include <stdio.h>#include <string.h>#define MAXNUM 100000int prime_number = 0;int prime_list[MAXNUM]; bool is_prime[MAXNUM]; int ans[MAXNUM + 2];int dp[MAXNUM + 2];void set_prime() {int i, j;memset(is_prime, 0, sizeof(is_prime));for (i = 2; i < MAXNUM; i++) {if (is_prime[i] == 0) {prime_list[prime_number++] = i;if (i >= MAXNUM / i) continue;for (j = i * i; j < MAXNUM; j+=i) {is_prime[j] = 1;}}}}int main() {int i, j, k,o=0,d[100];memset(dp, -1, sizeof(dp));set_prime();ans[0] = 0;dp[1] = 0;for (i = 1; i <= MAXNUM; i++) {ans[i] = ans[i - 1] + dp[i];if (dp[i + 1] == -1 || dp[i + 1] > dp[i] + 1) {dp[i + 1] = dp[i] + 1;}for (j = 0; j < prime_number; j++) {if (i > MAXNUM / prime_list[j]) break;k = i * prime_list[j];if (dp[k] == -1 || dp[k] > dp[i] + 1) {dp[k] = dp[i] + 1;}}}while (scanf("%d%d", &i, &j) == 2 && (i || j)) { d[o]=ans[j] - ans[i - 1];o++;}for(i=0;i<o;i++)printf("%d\n",d[i]);}14.Graveyard#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){int a[100],b[100],n,i,j;double s,p,l,t;for(i=0;;i++){scanf("%d%d",&a[i],&b[i]);if(a[i]==0&&b[i]==0) break;}n=i;for(i=0;i<n;i++){p=10000;if(b[i]%a[i]==0){printf("0.0000\n");continue;};t=10000/((double)a[i]);for(j=1;j<a[i]+b[i];j++){l=10000/((double)(a[i]+b[i]));l=t-j*l;l=fabs(l);if(l<p) p=l;}s=(a[i]-1)*p;printf("%.4lf\n",s);}return 0;}15.Hailstone#include <stdio.h>#include <stdlib.h>#include <string.h>int f(int n){int s=1;while(1){if(n==1) return s;else if(n%2==0) n=n/2,s++;else n=3*n+1,s++;}}int main()int n,m,i,j=0,t;scanf("%d%d",&m,&n);printf("%d %d",m,n);if(m>n) t=m,m=n,n=t;for(i=m;i<=n;i++)if(f(i)>j) j=f(i);printf(" %d",j);return 0;}16.Hanoi Ⅱ#include <stdio.h>#include <stdlib.h>#define M 70int start[M], targe[M];long long f(int *p, int k, int fina){if(k==0) return 0;if(p[k]==fina) return f(p,k-1,fina); return f(p,k-1,6-fina-p[k])+(1LL<<(k-1));int main (){long long ans;int n;while(scanf("%d",&n),n){int i;for(i=1;i<=n;i++) scanf("%d",&start[i]);for(i=1;i<=n;i++) scanf("%d",&targe[i]);int c=n;for(;c>=1&&start[c]==targe[c];c--);if(c==0){printf("0\n"); continue;}int other=6-start[c]-targe[c];ans=f(start,c-1,other)+f(targe,c-1,other)+1;printf("%lld\n",ans);}return 0;}17.Houseboat#include <stdio.h>#include <stdlib.h>#include <math.h>#define pi 3.1415926int f(float x,float y){int i;for(i=0;;i++)if(50*i>sqrt(x*x+y*y)*sqrt(x*x+y*y)*pi/2) break;return i;}int main(){int n,i,a[100];float x,y;scanf("%d",&n);for(i=0;i<n;i++){scanf("%f%f",&x,&y);a[i]=f(x,y);}for(i=0;i<n;i++)printf("%d %d\n",i+1,a[i]);return 0;}18.Music Composer19.Redistribute wealth#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){int a[1000],b[1000],n,i,j,s,sum,t,m,mid,c[100],k=0;while(1){scanf("%d",&n);if(n==0) break;{s=0;for(i=1;i<=n;i++){scanf("%d",&a[i]);s=s+a[i];}m=s/n;b[1]=a[1]-m;b[0]=0;for(i=2;i<n;++i)b[i]=b[i-1]+a[i]-m;for(i=0;i<n;i++)for(j=0;j<n-1-i;j++)if(b[j]>b[j+1]) t=b[j],b[j]=b[j+1],b[j+1]=t;mid=b[n/2];sum=0;for(i=0;i<=n-1;++i) sum=sum+fabs(mid-b[i]);c[k]=sum;k++;}}for(i=0;i<k;i++) printf("%d\n",c[i]);return 0;}20.Road trip#include <stdio.h>#include <stdlib.h>#include <math.h>int f(int n){int a[100],b[100],i,s;for(i=0;i<n;i++)scanf("%d%d",&a[i],&b[i]);s=a[0]*b[0];for(i=1;i<n;i++)s=s+a[i]*(b[i]-b[i-1]);return s;}int main(){int n,c[100],i=0;while(1){scanf("%d",&n);if(n==-1) break;c[i]=f(n);i++;}n=i;for(i=0;i<n;i++)printf("%d\n",c[i]);return 0;}21.Scoring#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){int i,j,sum,min,c,count,n,a,b;char s1[50],s2[50];scanf("%d",&n);for(i=0;i<n;i++){count=sum=0;scanf("%s",s2);for(j=0;j<4;j++){scanf("%d%d",&a,&b);if(b!=0){sum+=(a-1)*20+b;count++;}}if(i==0){c=count,min=sum;strcpy(s1,s2);}else if(count>c||(count==c&&sum<min)){min=sum;c=count;strcpy(s1,s2);}}printf("%s %d %d\n",s1,c,min);return 0;}22.Specialized Numbers#include <stdio.h>#include <stdlib.h>int main(){int i,n,sum10,sum12,sum16;for(i=2992;i<3000;i++){n=i;sum10=0;while(n){sum10+=n%10;n/=10;}n=i;sum12=0;while(n){sum12+=n%12;n/=12;}n=i;sum16=0;while(n){sum16+=n%16;n/=16;}if(sum10==sum12&&sum12==sum16) printf("%d\n",i);}return 0;}23.Sticks#include <stdio.h>#include <string.h>#include <stdlib.h>int len[64], n, minlen, get;bool b[64];int cmp(const void *a, const void *b){return *(int *)a < *(int *)b ? 1 : -1;}bool dfs(int nowlen, int nowget, int cnt){if(cnt >= n) return false;if(get == nowget) return true;int i;bool f = false;if(nowlen == 0) f = true;for(i = cnt; i < n; i++){if(!b[i]){if(len[i] + nowlen == minlen){b[i] = true;if(dfs(0, nowget+1, nowget))return true;b[i] = false;return false;}else if(len[i] + nowlen < minlen){b[i] = true;if(dfs(nowlen+len[i], nowget, i+1))return true;b[i] = false;if(f) return false;while(i + 1 < n && len[i] == len[i+1]) i++;}}}return false;}int main(){int i, tollen;while(scanf("%d", &n), n){tollen = 0;int j = 0, p;for(i = 0; i < n; i++){scanf("%d", &p);if(p <= 50)len[j] = p;tollen += len[j];j++;}}n = j;if(n == 0){printf("0\n");continue;}qsort(len, n, sizeof(int), cmp);for(minlen = len[0]; ; minlen++) {if(tollen % minlen) continue;memset(b, 0, sizeof(b));get = tollen / minlen;if(dfs(0, 0, 0)){printf("%d\n", minlen);break;}}return 0;}24.Sum of Consecutive#include <stdio.h>#include <stdlib.h>#include <string.h>int len[64],n,minlen,get;int b[64];int cmp(const void *a,const void *b) {return *(int *)a<*(int *)b?1:-1; }int dfs(int nowlen,int nowget,int cnt) {if(cnt>=n) return 0;if(get==nowget) return 1;int i,f=0;if(nowlen==0) f=1;for(i=cnt;i<n;i++){if(len[i]+nowlen==minlen){b[i]=1;if(dfs(0,nowget+1,nowget)) return 1;b[i]=0;return 0;}else if(len[i]+nowlen<minlen){b[i]=1;if(dfs(nowlen+len[i],nowget,i+1)) return 1;b[i]=0;if(f) return 0;while(i+1<n&&len[i]==len[i+1]) i++;}}return 0;}int main(){int i,tollen,q=0,c[100];while(scanf("%d",&n),n){tollen=0;int j=0,p;for(i=0;i<n;i++){scanf("%d",&p);if(p<=50){len[j]=p;tollen+=len[j];j++;}}n=j;if(n==0){printf("0\n"); continue;}qsort(len,n,sizeof(int),cmp); for(minlen=len[0];;minlen++){ if(tollen%minlen) continue;memset(b,0,sizeof(b));get=tollen/minlen;if(dfs(0,0,0)){c[q]=minlen;q++;break;}}}for(i=0;i<q;i++)printf("%d\n",c[i]);return 0;}25.Symmetric Sort#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){double A[100];int i=0,j=0,k=0,l=0,sum=0;while(1){scanf("%lf",&A[i]);if(A[i]==0)break;i++;}for(j=0;j<i;j++){if(A[j]==2)printf("1\n");else{int B[10000],m=1,number=0;double n;B[0]=2;for(k=3;k<=A[j];k+=2){n=(double)k;for(l=2;l<=sqrt(n);l++){if(k%l==0)goto ai;}B[m]=k;m++;ai:;}for(k=0;k<m;k++){sum=0;for(l=k;l<m;l++){sum+=B[l];if(sum==A[j]){number++;break;}}}printf("%d\n",number);}}return 0;}26.The Clock#include <stdio.h>#include <stdlib.h>#include <string.h>int main()char s[100][100],a[100];int i,j,n;scanf("%d",&n);for(i=0;i<n;i++) scanf("%s",s[i]);for(i=0;i<n-1;i++)for(j=0;j<n-1-i;j++)if(strlen(s[i])>strlen(s[i+1]))strcpy(a,s[i]),strcpy(s[i],s[i+1]),strcpy(s[i+1],a);if(n%2==0){for(i=0;i<n-1;i=i+2) printf("%s ",s[i]);printf("%s ",s[n-1]);for(i=i-3;i>0;i=i-2) printf("%s ",s[i]);}else{for(i=0;i<n-1;i=i+2) printf("%s ",s[i]);printf("%s ",s[n-1]);for(i=i-1;i>0;i=i-2) printf("%s ",s[i]);}return 0;}27.The Ratio of gainers to losers #include<stdio.h>int main(){char s[5];int i,sum=0;gets(s);for(i=0;s[i]!='\0';i++){switch(s[i]){case'I': sum+=1;break;case'V': sum=5-sum;break; case'X':sum=10-sum;break; }}printf("%d\n",sum);return 0;}28.VOL大学乒乓球比赛#include <stdio.h>#include <stdlib.h>int main(){printf("A=Z\nB=X\nC=Y\n");return 0;}29.毕业设计论文打印#include <stdio.h>#include <stdlib.h>int main(){int a[100],j=1,i,n,m;scanf("%d%d",&n,&m);for(i=0;i<n;i++)scanf("%d",&a[i]);for(i=0;i<n;i++)if(a[i]>a[m]) j++;printf("%d",j++);return 0;}30.边沿与内芯的差#include <stdio.h>#include <stdlib.h>int main(){int A[100][100],i,j,m,n,s=0,t=0;scanf("%d%d",&n,&m);for(i=1;i<=n;i++){for(j=1;j<=m;j++){scanf("%d",&A[i][j]);}}for(i=2;i<m;i++)s=s+A[1][i];for(i=2;i<m;i++)s=s+A[n][i];for(i=1;i<=n;i++)s=s+A[i][1];for(i=1;i<=n;i++)。

2021全国大学生英语竞赛C类样题答案

2021全国大学生英语竞赛C类样题答案

2021National English Competitionfor College Students(Type C-Sample)参考答案及作文评分标准Part I Listening Comprehension(30marks)Section A(5marks)1—5CBCDDSection B(10marks)6—10TFFTF11—15CDABCSection C(5marks)16—20BBCDBSection D(10marks)21.its disappearance22.have no idea23.actual bined25.slightly unclear Summary26.abandoned27.subway system28.being renovated29.Brooklyn Bridge Station30.significancePart II Vocabulary and Structures(15marks)31―35CBCAB36―40CCBAD41―45ABDCAPart III Cloze(10marks)46.covering47.both48.eventually49.mistakenly50.through51.hungry52.scientific53.sleepiness54.connection55.evilPart IV Reading Comprehension(30marks)Section A56—60EACGBSection B61.On the5th day of the5th lunar month every year.62.Li Sao,Tian Wen,and Jiu Ge.63.In278BC,he heard the news that Qin troops had finally conquered Chu蒺s capital,so he plunged himself into the Miluo River64.People hold dragon boat racing,eat zongzi and drink realgar wine on that day.65.They are said to be able to ward off evil.Section C66.presumption of innocence67.accused person68.reach a verdict69.biases70.fundamental human rightPart V Translation (10marks)71.“有旧,有新,有借,有蓝;在一只鞋子里放一枚六便士的银币。

NOJ100题+解答

NOJ100题+解答

#include<stdio.h>int main(){int a,b,sum;scanf("%d%d",&a,&b); sum=a+b;printf("%d\n",sum);return 0;}#include<stdio.h>#define PI 3.1415926int main(){double r,h,l,s,sq,vq,vz;scanf("%lf%lf",&r,&h);l=2*PI*r;s=PI*r*r;sq=4*PI*r*r;vq=PI*r*r*r*4/3;vz=PI*r*r*h;printf("%.2lf\n%.2lf\n%.2lf\n%.2lf\n%.2lf\n",l,s,sq,vq,vz); return 0;}#include<stdio.h>int main(){double ma,eng,c,sum,ave;scanf("%lf%lf%lf",&ma,&eng,&c); sum=ma+eng+c;ave=sum/3;printf("%lf\n%lf\n",sum,ave);return 0;}#include<stdio.h>int main(){int a,b,c,m;scanf("%d%d%d",&a,&b,&c); if (a>b) m=a;else m=b;if (m<c) m=c;printf("%d",m);return 0;}#include<stdio.h>int main(){int n;scanf("%d",&n);if ((1000<n<10000)&&(n/1000==n%10)&&(n/100%10==n/10%10)) printf("yes\n"); else if((100<n<=1000)&&(n/100==n%10)) printf("yes\n");else if((10<n<=100)&&(n/10==n%10)) printf("yes\n");else if(0<n<=10) printf("yes\n");else printf("no\n");return 0;}#include<stdio.h>int main(){double l,bon;scanf("%lf",&l);if(l<=10) bon=l*0.1;else if(l<20) bon=1+(l-10)*0.075;else if(l<40) bon=1.75+(l-20)*0.05; else if(l<60) bon=2.75+(l-40)*0.03; else if(l<100) bon=3.35+(l-60)*0.015; else bon=3.95+(l-100)*0.01;printf("%lf\n",bon);return 0;}用ceil函数,向上取整#include<stdio.h>int main(){double d,m;scanf("%lf",&d);if(d<=2) m=7;else if(d<=15){if(d-2==(int)(d-2)) m=7+(d-2)*1.5;else m=7+((int)(d-2)+1)*1.5;}else if(d-15==(int)(d-15)) m=26.5+(d-15)*2.1; else m=26.5+((int)(d-15)+1)*2.1;printf("%lf\n",m);return 0;}#include<stdio.h>int main(){int y,m,d,Days,sum;scanf("%d-%d-%d",&y,&m,&d);if((y%4==0&&y%100!=0)||(y%400==0)) Days=29; else Days=28;switch(m){case 1:sum=d;break;case 2:sum=31+d;break;case 3:sum=31+Days+d;break;case 4:sum=62+Days+d;break;case 5:sum=92+Days+d;break;case 6:sum=123+Days+d;break;case 7:sum=153+Days+d;break;case 8:sum=184+Days+d;break;case 9:sum=215+Days+d;break;case 10:sum=245+Days+d;break;case 11:sum=276+Days+d;break;case 12:sum=307+Days+d;break;}printf("%d\n",sum);return 0;}#include<stdio.h>int main(){int i;scanf("%d",&i);if(i>=90) printf("A\n");else if(i>=80) printf("B\n"); else if(i>=70) printf("C\n"); else if(i>=60) printf("D\n"); else printf("E\n");return 0;}#include<stdio.h>int main(){double x,y;scanf("%lf,%lf",&x,&y);if((x-2)*(x-2)+(y-2)*(y-2)<=1) printf("10");else if((x-2)*(x-2)+(y+2)*(y+2)<=1) printf("10"); else if((x+2)*(x+2)+(y-2)*(y-2)<=1) printf("10"); else if((x+2)*(x+2)+(y+2)*(y+2)<=1) printf("10"); else printf("0");return 0;}#include<stdio.h>int main(){double l,x,r;scanf("%lf %lf",&l,&r);while((2*l*l*l-4*l*l+3*l-6)!=0&&(2*r*r*r-4*r*r+3*r-6)!=0){ x=(l+r)/2;if((2*l*l*l-4*l*l+3*l-6)*(2*x*x*x-4*x*x+3*x-6)<=0)r=x;else l=x;}if(2*l*l*l-4*l*l+3*l-6==0) printf("%.2lf",l);else printf("%.2lf",r);return 0;}#include<stdio.h>#include<math.h>int main(){int i=800,t=2,cnt=0,sum=0;double e=-1;while(i>=500){while(t<=i-1){if(i%t==0) break;t++;}if(t==i) e=pow(-1,cnt),sum=sum+e*i,cnt++; i--;t=2;}printf("%d %d",cnt,sum);return 0;}#include<stdio.h>#include<math.h>int main(){int a=1;double b=1,pi=0,c=1;while(fabs(c)>=1e-6)pi=pi+c,b=b+2,a=-a,c=a/b; pi=pi*4;printf("%lf\n",pi);return 0;}#include<stdio.h>int main(){int a1=1,a2=1,n=2,sum=2,t; while(sum<=100){t=a1;a1=a2;a2=t+2*a2;sum=sum+a2;n++;}printf("%d\n",n-1);while(sum<=1000){t=a1;a1=a2;a2=t+2*a2;sum=sum+a2;n++;}printf("%d\n",n-1);while(sum<=10000){t=a1;a1=a2;a2=t+2*a2;sum=sum+a2;n++;}printf("%d\n",n-1);}#include<stdio.h>int main(){int x,a,s,n=1;scanf("%d %d",&x,&a);s=x;if(a!=0){for(;n<a;n++){s=s*x;if(s>=1000) s=s/100%10*100+s/10%10*10+s%10; }}printf("%d\n",s);return 0;}#include<stdio.h>int main(){int m,n,s;scanf("%d",&n);s=n*n*n;printf("%d*%d*%d=%d=",n,n,n,s);for(m=1;s!=n*m;m++);if(n%2==1){for(s=-n/2;s<n/2;s++)printf("%d+",m+2*s);printf("%d",m+n/2*2);}else{for(s=-n/2;s<n/2-1;s++)printf("%d+",m+s*2+1); printf("%d",m+(n/2-1)*2+1);}return 0;}#include<stdio.h>int main(){char a,b,c,x,y,z;a='A',b='B',c='C',x='X',y='Y',z='Z'; printf("%c=%c\n",a,z);printf("%c=%c\n",b,x);printf("%c=%c\n",c,y);return 0;}#include<stdio.h>int main(){int a,b,t;scanf("%d %d",&a,&b);if(a>b)t=a,a=b,b=t;for(;a<b;a++){for(t=2;t<a;t++)if(a%t==0) break; if(t==a)printf("%d ",a);}return 0;}#include<stdio.h>int main(){int n=1;double a1=1,a2=2,a3,sum=2; while(n<=19){a3=a1+a2;sum=sum+a3/a2;a1=a2;a2=a3;n++;}printf("%lf\n",sum);return 0;}#include<stdio.h>#include<math.h> int main(){double a;int n=0;scanf("%lf",&a);a=fabs(a);if(a<=1)printf("0\n"); else{while(a>1){a=a/10;n++;}printf("%d\n",n); }return 0;}#include<stdio.h>int main(){int a=1,b=0,t,m,n=0; scanf("%d",&t);while(n<t){m=b;b=3*a+2*b;a=m;n++;}printf("%d %d",a,b); return 0;}#include<stdio.h>#include<math.h>int main(){int n;int f(int n);scanf("%d",&n);printf("%d\n",f(n));}int f(int n){int a;if(n==1||n==2)a=0;else if(n==3)a=1;else if(n==4)a=3;elsea=f(n-1)*2+pow(2,n-4)-f(n-4); return a;}#include<stdio.h>int main(){int n,x=1234,y=1,a,b,c,d,e,f,g,h,i,j;scanf("%d",&n);for(;x<49383&&y<98765;x++){y=x*n;a=x/10000%10;b=x/1000%10;c=x/100%10;d=x/10%10;e=x%10;f=y/10000%10;g=y/1000%10;h=y/100%10;i=y/10%10;j=y%10;if(a==b||a==c||a==d||a==e||a==f||a==g||a==h||a==i||a==j) continue; if(b==c||b==d||b==e||b==f||b==g||b==h||b==i||b==j) continue;if(c==d||c==e||c==f||c==g||c==h||c==i||c==j) continue;if(d==e||d==f||d==g||d==h||d==i||d==j) continue;if(e==f||e==g||e==h||e==i||e==j) continue;if(f==g||f==h||f==i||f==j) continue;if(g==h||g==i||g==j) continue;if(h==i||h==j) continue;if(i==j) continue;printf("%05d/%05d=%d\n",y,x,n); }return 0;}#include<stdio.h>#include<stdlib.h>#include<math.h>int main(){int m,n,i;double x,s=0;scanf("%d%d",&n,&m);for(i=n;i<=m;i++){x=pow(i,2.0);s=s+1/x;}printf("%.5lf\n",s);return 0;}#include<stdio.h>int main(){int x,y,a,b,L;double t;scanf("%d%d%d%d%d",&x,&y,&a,&b,&L); if(a==b) printf("impossible\n");else if(x>y){if(a>b)y=L-x+y,t=(double)y/(a-b);else y=x-y,t=(double)y/(b-a);if((int)t==t)printf("%d\n",(int)t);else printf("%lf\n",t);}else {if(a>b)y=y-x,t=(double)y/(a-b);else y=L-y+x,t=(double)y/(b-a);if((int)t==t)printf("%d\n",(int)t);else printf("%lf\n",t);}return 0;}#include<stdio.h>int _max(int a,int b){return a>b?a:b;}int a[20];int f[20][20];int main(){int n,i,j,s=0;scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&a[i]);for(j=1;j<n;j++)f[0][0]=a[0],f[0][j]=f[0][j-1]*a[j]; for(i=1;i<n;i++){f[i][i-1]=1;for(j=i;j<n;j++)f[i][j]=f[i][j-1]*a[j];}for(i=0;i<n;i++)for(j=i;j<n;j++)s=_max(s,f[i][j]);if(s==0)printf("-1\n");else printf("%d\n",s);return 0;}#include<stdio.h>int main(){int x=192,y,z,a,b,c,d,e,f,g,h,i;for(;x<328;x++){y=2*x;z=3*x;a=x/100%10;b=x/10%10;c=x%10;d=y/100%10;e=y/10%10;f=y%10;g=z/100%10;h=z/10%10;i=z%10;if(a==b||a==c||a==d||a==e||a==f||a==g||a==h||a==i||a==0) continue; if(b==c||b==d||b==e||b==f||b==g||b==h||b==i||b==0) continue;if(c==d||c==e||c==f||c==g||c==h||c==i||c==0) continue;if(d==e||d==f||d==g||d==h||d==i||d==0) continue;if(e==f||e==g||e==h||e==i||e==0) continue;if(f==g||f==h||f==i||f==0) continue;if(g==h||g==i||g==0) continue;if(h==i||h==0) continue;printf("%d %d %d\n",x,y,z);}return 0;}#include<stdio.h>int main(){int a,b,c,sum=10;scanf("%d%d%d",&a,&b,&c);for(;sum<=100;sum++){if(sum%3==a&&sum%5==b&&sum%7==c){ printf("%d\n",sum); break;}}if(sum==101)printf("-1\n");return 0;}#include<stdio.h>#include<math.h>int main(){int ce,y,m,n,a=0;scanf("%d",&n);for(ce=0;;ce+=100){for(y=ce+1;y<ce+100;y+=2){ for(m=3;m<sqrt(y);m+=2){ if(y%m==0) break;}if(m>=sqrt(y)) break;}if(y==ce+101) a++;if(a==n) break;}printf("%d %d\n",ce,ce+99); return 0;}#include<stdio.h>int main(){int n,i;scanf("%d",&n);for(i=1;i<=n;i++){if(i%7==0) printf("%d ",i);else if(i/1000%10==7||i/100%10==7||i/10%10==7||i%10==7) printf("%d ",i); }return 0;}#include<stdio.h>double a[100000000];int main(){int n,i;double ave,sum=0;scanf("%d",&n);for(i=0;i<n;i++){scanf("%lf",&a[i]);sum=sum+a[i];}ave=sum/n;for(i=0,sum=0;i<n;i++)sum=sum+(a[i]-ave)*(a[i]-ave); printf("%lf\n",sum);return 0;}#include<stdio.h>int f[100000000];int main(){int n,i;scanf("%d",&n);for(i=0;i<n;i++){int a,b;scanf("%d%d",&a,&b);f[i]=a+b;}for(i=0;i<n;i++){if(f[i]>100) f[i]=f[i]/10%10*10+f[i]%10,printf("%d\n",f[i]); else printf("%d\n",f[i]);}return 0;}#include<stdio.h>#include<math.h>int getbit(int n,int k) {n=n>>k-1;return n&1;}int main(){int n,k;scanf("%d%d",&n,&k); printf("%d",getbit(n,k)); return 0;}#include<stdio.h>int _min(int n){int i=0;if(n>=100) i=n/100%10,n=n/10%10*10+n%10; if(n>=50) i+=1,n-=50;if(n>=10) i+=n/10%10,n%=10;if(n>=5) i+=1,n-=5;if(n>=2) i+=n/2,n%=2;if(n==1) i+=1;return i;}int f[100];int main(){int n,i,sum;scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&f[i]);for(sum=0,i=0;i<n;i++)sum=sum+_min(f[i]);printf("%d\n",sum);return 0;}#include<stdio.h>int fceil(double x){if(x>0){if((int)x==x) return x; else return (int)x+1; }else return (int)x;}int main(){double x;scanf("%lf",&x);printf("%d\n",fceil(x)); return 0;}#include<stdio.h>int _move(int value,int n){int t;if(n>0)t=value>>n|value<<32-n;else {n=-n;t=value<<n|value>>32-n;}return t;}int main(){int value,n;scanf("%d%d",&value,&n);printf("%d\n",_move(value,n)); return 0;}#include<stdio.h>void timesum(int AH,int AM,int AS,int BH,int BM,int BS){int h=0,m=0,s=0;if(AS+BS>59) s=(AS+BS)-60,m++;else s=AS+BS;if(AM+BM>59) m+=((AM+BM)-60),h++;else m=AM+BM;h+=(AH+BH);printf("%d %d %d\n",h,m,s);}int main(){int AH,AM,AS,BH,BM,BS;scanf("%d%d%d%d%d%d",&AH,&AM,&AS,&BH,&BM,&BS); timesum(AH,AM,AS,BH,BM,BS);return 0;}#include<stdio.h> void f(long int n) {int m;m=n%10;printf("%d",m); n/=10;if(n!=0) f(n);}int main(){long int n;scanf("%d",&n); f(n);return 0;}#include<stdio.h>int getfloor(double x){if(x>0) return (int)x;else return (int)x-1;}int main(){double x;scanf("%lf",&x);printf("%d\n",getfloor(x)); return 0;}#include<stdio.h>inline int xchg(unsigned char n) {n=n>>4|n<<4;return n;}int main(){unsigned char n;scanf("%d",&n);printf("%d\n",xchg(n));return 0;}#include<stdio.h>void QuickSort(int A[100],int s,int m) {int i,t;for(;s<=m;s++){for(i=s;i<=m;i++)if(A[s]<A[i]){t=A[s];A[s]=A[i];A[i]=t;}printf("%d ",A[s]);}}int main(){int s,m,n,i,A[100];scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&A[i]);scanf("%d%d",&s,&m);for(i=0;i<s;i++)printf("%d ",A[i]);QuickSort(A,s,m);for(i=m+1;i<n;i++)printf("%d ",A[i]);return 0;}#include<stdio.h>double avg(int A[100],int s,int e) {double sum;for(sum=0;s<=e;s++)sum=sum+A[s];return sum;}int main(){int A[100],s,e,i,n;double a;scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&A[i]);scanf("%d%d",&s,&e);a=avg(A,s,e)/(e-s+1);printf("%lf\n",a);return 0;}#include<stdio.h>int main(){int n,a[100],i,j,s=0,t=0; scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&a[i]);for(i=0;i<n-1;i++)for(j=i+1;j<n;j++){if(a[i]>a[j]) s++;else if(a[i]<a[j]) t++; }s=s>t?t:s;printf("%d\n",s);return 0;}#include<stdio.h>void SelectionSort(int A[],int s,int m) {int i,t,n;for(n=s;n<=s+m-1;n++){for(i=n;i<=s+m-1;i++)if(A[n]<A[i]){t=A[n];A[n]=A[i];A[i]=t;}printf("%d ",A[n]);}}int main(){int s,m,n,i,A[100];scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&A[i]);scanf("%d%d",&s,&m);for(i=0;i<s;i++)SelectionSort(A,s,m);for(i=m+1;i<n;i++)printf("%d ",A[i]);return 0;}#include<stdio.h>void SelectionSort(int A[],int s,int m) {int i,t,n;for(n=s;n<=s+m-1;n++){for(i=n;i<=s+m-1;i++)if(A[n]<A[i]){t=A[n];A[n]=A[i];A[i]=t;}printf("%d ",A[n]);}}int main(){scanf("%d",&n);for(i=0;i<n;i++)scanf("%d",&A[i]);scanf("%d%d",&s,&m); for(i=0;i<s;i++)printf("%d ",A[i]);SelectionSort(A,s,m); for(i=m+1;i<n;i++)printf("%d ",A[i]);return 0;}#include<stdio.h>int main(){int a[100][100],n,i,j;scanf("%d",&n);for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%d",&a[i][j]); for(i=0;i<n;i++)for(j=0;j<n;j++){if(j<n-i-1) printf(" ");else printf("%d ",a[i][j]); if(j==n-1) printf("\n"); }return 0;}#include<stdio.h>int main(){int a[100][100],n,i,j;scanf("%d",&n);for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%d",&a[i][j]); for(i=0;i<n;i++)for(j=0;j<n;j++){if(j<i) printf(" ");else printf("%d ",a[i][j]); if(j==n-1) printf("\n"); }return 0;}#include<stdio.h>int main(){int a[100][100],n,i,j;scanf("%d",&n);for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%d",&a[i][j]); for(i=0;i<n;i++)for(j=0;j<n;j++){if(j>n-i-1) printf(" ");else printf("%d ",a[i][j]); if(j==n-1) printf("\n"); }return 0;}#include<stdio.h>int main(){int a[100][100],n,m,i,j,s1,s2; scanf("%d%d",&n,&m);for(i=0;i<n;i++)for(j=0;j<m;j++)scanf("%d",&a[i][j]);for(j=0,s1=0;j<m;j++)s1=s1+a[0][j]+a[n-1][j];for(i=1,s2=0;i<n-1;i++){s1=s1+a[i][0]+a[i][m-1];for(j=1;j<m-1;j++)s2=s2+a[i][j];}printf("%d\n",s1-s2);return 0;}#include<stdio.h>int main(){int a[100],b[100],i,j,n; scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&a[i]); b[i]=a[i];}for(i=1;i<n;i+=2)printf("%d ",b[i]);return 0;}。

标准c程序设计第6版答案

标准c程序设计第6版答案

标准C程序设计第6版答案1. 简介本文档是《标准C程序设计第6版》一书的答案,旨在辅助读者理解和掌握书中的内容。

在学习C程序设计过程中,参考答案可以帮助读者检验自己的理解程度,加深对知识点的理解,并提供一种解题思路。

2. 第一章简介2.1 问题1答案:C语言是一种通用的计算机编程语言,广泛应用于系统软件、嵌入式系统、驱动程序等领域。

C语言被广泛使用的原因有以下几点: - 简洁高效:C语言的语法简洁,易于学习和理解。

同时,C语言的执行效率高,生成的机器代码精简,执行速度快。

- 跨平台:C语言具有很强的可移植性,可以在不同的操作系统和硬件平台上编写和运行程序。

- 底层控制能力:C语言支持直接操作内存和硬件设备,适用于需要对底层进行精确控制的场景。

- 丰富的函数库:C语言拥有丰富的函数库,方便开发者进行程序开发。

2.2 问题2答案:C语言是由贝尔实验室的Dennis Ritchie和Ken Thompson在20世纪70年代开发的。

起初,C语言是为Unix操作系统开发的,但由于其简洁高效的特点,迅速流行起来,并成为广泛应用的编程语言。

2.3 问题3答案:C语言是一种面向过程的编程语言。

它将问题分解为若干个子过程,通过调用这些子过程来解决问题。

C语言的面向过程特点使得程序的组织结构清晰,易于理解和维护。

3. 第二章程序框图与程序步骤图3.1 问题4答案:程序框图(program flowchart)是一种图形化的表示程序流程的工具。

它用不同的图形符号表示各种程序控制结构,如顺序结构、选择结构和循环结构。

程序框图通过连接这些图形符号来表示程序的执行顺序。

程序框图提供了一种清晰的视觉方式,帮助开发者理解程序的结构和流程。

3.2 问题5答案:程序步骤图(program flowchart)是一种图形化的表示程序运行步骤的工具。

它使用方框表示程序的每一步骤,通过箭头表示各个步骤之间的逻辑关系。

程序步骤图主要用于描述程序的逻辑流程,帮助开发者理解和分析程序的执行过程。

C程序设计教程第二版习题答案

C程序设计教程第二版习题答案

C程序设计教程第二版习题答案第1章:C语言概述1. 简述C语言的特点。

- C语言是一种结构化编程语言,具有高效、灵活、功能强大等特点。

它支持多种编程范式,包括过程式、面向对象和泛型编程。

2. C语言的发展历史。

- C语言由丹尼斯·里奇在20世纪70年代初期开发,最初用于UNIX操作系统的编写。

随着UNIX的流行,C语言也逐渐普及。

第2章:C语言基础1. 变量声明的规则。

- 变量声明必须指定数据类型,变量名必须以字母或下划线开头,可以包含字母、数字和下划线,但数字不能作为变量名的首位。

2. 常量的使用。

- 常量是在程序执行过程中不能被修改的值,可以用#define预处理指令定义,或者直接使用字面量。

第3章:控制语句1. if语句的使用。

- if语句用于根据条件执行不同的代码块。

基本语法为:`if (条件) { 执行代码 }`。

2. switch语句的使用。

- switch语句用于根据变量的值执行不同的代码块。

基本语法为:`switch (变量) { case 值1: 执行代码1; break; ... }`。

第4章:循环语句1. for循环的使用。

- for循环用于重复执行一段代码直到满足特定条件。

基本语法为:`for (初始化; 条件; 增量/减量) { 执行代码 }`。

2. while循环的使用。

- while循环在条件为真时重复执行代码块。

基本语法为:`while (条件) { 执行代码 }`。

第5章:函数1. 函数的定义和调用。

- 函数是一段具有特定功能的代码块,可以被重复调用。

定义函数的基本语法为:`返回类型函数名(参数列表) { 函数体 }`。

调用函数时使用:`函数名(参数)`。

2. 函数的参数传递。

- 参数传递可以是值传递或引用传递。

值传递时,函数内部对参数的修改不会影响到外部变量的值;引用传递则相反。

第6章:数组1. 一维数组的声明和使用。

- 一维数组的声明语法为:`类型数组名[大小]`。

西工大noj答案

西工大noj答案

西工大noj答案【篇一:西工大poj100题(全新)】圆及圆球等的相关计算#includestdio.hint main(){int a,b,sum;scanf(%d %d,a,b);sum=a+b;printf(%d,sum); }#includestdio.hint main(){float r,h,l,s,sq,vq,vz,pi=3.141592653; scanf(%f %f,r,h);l=2*pi*r;s=pi*r*r;【篇二:西北工业大学 c语言 poj题目及答案_第一季】>毋庸置疑,学习程序设计就是奔着“程序员梦”去的。

编程本质是运用计算机科学的基本思想求解问题、设计系统以及理解人类的思维行为和普适技能,核心是“实现”。

因此,诸如“中国梦”、“程序员梦”是编写出来,即“coding now,programming future”。

在这个学期,你将尝试用“编写”的方式去“实现”,体验与过去完全不同的“实现”。

在这个过程中,有太多的“if”不确定、有太多的“for”死循环、有太多的“bug”愁断魂,“实现”并不容易。

有人的地方就有江湖,有江湖的地方就有武林大会。

poj(problems online judge)是学编程的江湖。

在这里,做习题叫做“刷题”,习题做错叫做“被挖”(wa=wrong answer,结果错误),习题通过叫做“a了”(ac=accepted,结果通过),简单习题称为“水题”,“刷一圈”指连续刷题12小时以上。

总会有人用一、两周的时间完成100题的oj,这不叫“刷题”,叫“梦游”。

2012学年,一个大三的哥哥将100题的源码整理出版了(长安校区超市旁的复印店),大一亲们蜂拥而至,一时间“a4纸贵”,交叉着下载、复制、粘贴、上传的能力训练,唯独不见“编写”。

待到期末上机考试,亲们那双瞠目的眼睛与希望工程那双大眼睛神似,最终贡献了两位数的gdp。

有道是出来混的,迟早要还,哥哥今昔完美毕业,亲们继续“梦游”。

2013全国大学生英语竞赛C类决赛答案

2013全国大学生英语竞赛C类决赛答案

2013National English Contestfor College Students(Level C-Final)参考答案及作文评分标准Part I Listening Comprehension(30marks)Section A(5marks)1—5ACBBCSection B(10marks)6—10CCABA11—15BCBCASection C(5marks)16—20ACBACSection D(10marks)21.prescription22.drug addiction23.lenient approach24.distinguished between 25.are licensed to26.single transaction27.Proponents28.legitimate29.campaigns30.therebyPart II Vocabulary and Structure(15marks)31—35DBBCB36—40CABAD41—45ABACAPart III Cloze(10marks)46.height47.both48.surprising49.mistakenly50.through 51.hungry52.scientific53.Sleepiness54.connection55.evilPart IV Reading Comprehension(40marks)Section A(10marks)rmation59.gang60.requesting Section B(10marks)61.F62.T63.F64.It provides students with an online learning environment.65.They receive the individual support and advice they need to succeed in their study. Section C(10marks)66.enduring67.starved68.more dramatically69.D70.CSection D(10marks)71.Because the Egyptians worshiped cats as holy animals and there were laws protecting them.72.The Dark Ages in Europe.73.About 10percent.74.猫惯有“巫师的助手”之称。

西工大NOJ答案完全版

西工大NOJ答案完全版

输出A+B的结黑#i nclude<stdio.h>int main(){int a,b,sum;sca nf("%d%d",&a,&b);sum=a+b;prin tf("%d\n",sum); return 0; }#i nclude<stdio.h>#define PI 3.1415926int main(){double r,h,l,s,sq,vq,vz;sca nf("%lf%lf",&r,&h);l=2*PI*r;s=p|*r*r;sq=4*p|*r*r;vq=PI*r*r*r*4/3;vz=PI*r*r*h;prin tf("%.2lf\n%.2lf\n%.2lf\n%.2lf\n%.2lf\n",l,s,sq,vq,vz); return 0;}#i nclude<stdio.h>int main(){double ma,e ng,c,sum,ave;sca nf("%lf%lf%lf",&ma,&en g,&c); sum=ma+e ng+c; ave=sum/3;prin tf("%lf\n %lf\n",sum,ave); return 0;}#i nclude<stdio.h>int main(){int a,b,c,m;sca nf("%d%d%d",&a,&b,&c); if (a>b) m=a;else m=b;if (m<c) m=c;prin tf("%d",m);return 0;}#i nclude<stdio.h>int main(){int n;sca nf("%d",&n);if ((1000V n<10000)&&(n/1000==n%10)&&(n/100%10==n/10%10)) prin tf("y es\n");else if((100<n<=1000)&&(n/100==n%10)) printf("yes\n");else if((10< n <=100)&&(n/10==n%10)) pri ntf("yes\n");else if(0< n<=10) pri ntf("yes\n");else prin tf(" no\n");return 0;}#i nclude<stdio.h>int main(){double l,b on;sca nf("%lf",&l);if(|v=10) bon=1*0.1;else if(l<20) bo n=1+(l-10)*0.075; else if(l<40) bon=1.75+(1-20)*0.05; else if(l<60) bon=2.75+(1-40)*0.03; else if(l<100) bon=3.35+(1-60)*0.015; else bo n=3.95+(l-100)*0.01;prin tf("%lf\n",bo n);return 0;}输出为实型,帰留六惶小裁(单位为元)#i nclude<stdio.h>int main(){double d,m;sca nf("%lf",&d);if(d<=2) m=7;else if(d<=15){if(d-2==(i nt)(d-2)) m=7+(d-2)*1.5;else m=7+((i nt)(d-2)+1)*1.5;}else if(d-15==(int)(d-15)) m=26.5+(d-15)*2.1; else m=26.5+((i nt)(d-15)+1)*2.1;prin tf("%lf\n",m);return 0;}#i nclude<stdio.h>int main(){int y,m,d,Days,sum;sca nf("%d-%d-%d", &y,&m,&d);if((y%4==0&&y%100!=0)||(y%400==0)) Days=29; else Days=28; switch(m){case 1:sum=d;break;case 2:sum=31+d;break;case 3:sum=31+Days+d;break;case 4:sum=62+Days+d;break;case 5:sum=92+Days+d;break;case 6:sum=123+Days+d;break;case 7:sum=153+Days+d;break;case 8:sum=184+Days+d;break;case 9:sum=215+Days+d;break;case 10:sum=245+Days+d;break;case 11:sum=276+Days+d;break;case 12:sum=307+Days+d;break;}prin tf("%d\n",sum);return 0;}#i nclude<stdio.h>int main(){int i;sca nf("%d",&i);if(i>=90) prin tf("A\n");else if(i>=80) prin tf("B\n"); else if(i>=70) pri ntf("C\n"); else if(i>=60) prin tf("D\n"); else prin tf("E\n");return 0;}#i nclude<stdio.h>int main(){double x,y;sca nf("%lf,%lf", &x,&y);if((x-2)*(x-2)+(y-2)*(y-2)v=1) prin tf("10");else if((x-2)*(x-2)+(y+2)*(y+2)<=1) printf("10"); else if((x+2)*(x+2)+(y-2)*(y-2)<=1) printf("10"); else if((x+2)*(x+2)+(y+2)*(y+2)<=1) printf("10"); else prin tf("0");return 0;}输出根炬型・保留两性呷数.#i nclude<stdio.h>int main(){double l,x,r;sca nf("%lf %lf",&l,&r);while((2*l*l*l-4*l*l+3*l-6)!=0&&(2*r*r*r-4*r*r+3*r-6)!=0){ x=(l+r)/2;if((2*l*l*l-4*l*l+3*l-6)*(2*x*x*x-4*x*x+3*x-6)<=0)r=x;else l=x;}if(2*l*l*l-4*l*l+3*l-6==0) prin tf("%.2lf",l);else prin tf("%.2lf",r);return 0;}}#i nclude<stdio.h>#in clude<math.h>int main(){int i=800,t=2,c nt=0,sum=0;double e=-1;while(i>=500){while(t<=i-1){if(i%t==0) break;t++;}if(t==i) e=pow(-1,c nt),sum=sum+e*i,cnt++; i--;t=2;}prin tf("%d %d",cnt,sum);return 0;#i nclude<stdio.h>#in clude<math.h> int main(){int a=1;double b=1,pi=0,c=1;while(fabs(c)>=1e-6)pi=pi+c,b=b+2,a=-a,c=a/b; pi=pi*4; prin tf("%lf\n",pi); return 0;}}#i nclude<stdio.h>int main(){int a仁1,a2=1,n=2,sum=2,t; while(sum<=100){t=a1;a仁a2;a2=t+2*a2; sum=sum+a2;n++;}prin tf("%d\n", n-1);while(sum<=1000){t=a1;a仁a2;a2=t+2*a2; sum=sum+a2;n++;}prin tf("%d\n", n-1);while(sum<=10000){t=a1;a仁a2;a2=t+2*a2;}sum=sum+a2; n++;}prin tf("%d\n", n-1);}File Name :T01 Sxpp最次方数输出为整型.#i nclude<stdio.h>int main(){int x,a,s, n=1;scanf("%d %d",&x,&a);s=x;if(a!=O){for(; n<a;n++){s=s*x;if(s>=1000) s=s/100%10*100+s/10%10*10+s%10;}}prin tf("%d\n",s);return 0;輸出连腹奇蒙之和,格式如sa mple outputB示.#i nclude<stdio.h>int main(){int m, n,s;scan f("%d",&n);s=n*n*n;prin tf("%d*%d*%d=%d=" ,n,n,n ,s);for(m=1;s!=n*m;m++);if(n %2==1){for(s=-n/2;s< n/2;s++)pri ntf("%d+",m+2*s);prin tf("%d",m+n/2*2);}else{for(s=-n/2;s< n/2-1;s++)pri ntf("%d+",m+s*2+1); prin tf("%d",m+( n/2-1)*2+1);}}#i nclude<stdio.h>int main(){char a,b,c,x,y, z; a='A',b='B',c=C,x='X',y='Y',z='Z'; prin tf("%c=%c\n",a,z);prin tf("%c=%c\n",b,x);prin tf("%c=%c\n",c,y); return 0;}#i nclude<stdio.h>int main(){int a,b,t;sca nf("%d %d",&a,&b); if(a>b)t=a,a=b,b=t;for(;a<b;a++){ for(t=2;t<a;t++)if(a%t==0) break; if(t==a)pri ntf("%d ",a); }return 0;}#i nclude<stdio.h>int main(){int n=1;double a1= 1,a2=2,a3,sum=2; while( n<=19){a3=a1+a2;sum=sum+a3/a2;a仁a2;a2=a3;n++;}prin tf("%lf\n",sum);return 0;}}Input#i nclude<stdio.h>#in clude<math.h> int main() {double a;int n=0;sca nf("%lf",&a); a=fabs(a); if(a<=1)pri ntf("0\n"); else{while(a>1){ a=a/10;n++;}prin tf("%d\n", n);}#i nclude<stdio.h>int main(){int a=1,b=0,t, m,n=0; sca nf("%d", &t); while( n< t){ m=b; b=3*a+2*b;a=m;n++;}prin tf("%d %d",a,b); return 0;}}输出旅苣方法的数目#i nclude<stdio.h>#in clude<math.h> int main(){int n;int f(i nt n);sca nf("%d",&n);prin tf("%d\n",f( n));}int f(i nt n){int a;if(n==1|| n==2)a=0;else if(n==3)a=1;else if(n==4)a=3;elsea=f( n-1)*2+pow(2, n-4)-f( n-4); return a; }#i nclude<stdio.h>int main(){int n ,x=1234,y=1,a,b,c,d,e,f,g,h,i,j;sca nf("%d",&n);for(;x<49383&&y<98765;x++){y=x* n;a=x/10000%10; b=x/1000%10;c=x/100%10; d=x/10%10;e=x%10;f=y/10000%10; g=y/1000%10;h=y/100%10;i=y/10%10;j=y%10; if(a==b||a==c||a==d||a==e||a==f||a==g||a==h||a==i||a==j) con ti nue;if(b==c||b==d||b==e||b==f||b==g||b==h||b==i||b==j) con ti nue;if(c==d||c==e||c==f||c==g||c==h||c==i||c==j) con ti nue;if(d==e||d==f||d==g||d==h||d==i||d==j) con ti nue; if(e==f||e==g||e==h||e==i||e==j) con ti nue; if(f==g||f==h||f==i||f==j) con ti nue;if(g==h||g==i||g==j) continue;if(h==i||h==j) continue;if(i==j) continue;prin tf("%05d/%05d=%d\n",y,x, n); }return 0;}1 1 1/+(科十iy + +歹輪出计算绪果,赧鈕5粒小薮.#i nclude<stdio.h>#i nclude<stdlib.h>#in clude<math.h> int main(){in t m,n ,i;double x,s=0;sca nf("%d%d",&n,&m);for(i=n ;i<=m;i++){x=pow(i,2.0); s=s+1/x;}prin tf("%.5lf\n",s); return 0;}#i nclude<stdio.h>int main(){int x,y,a,b,L;double t;scan f("%d%d%d%d%d", &x, &y,&a,&b,&L); if(a==b) prin tf("impossible\n");else if(x>y){ if(a>b)y=L-x+y,t=(double)y/(a-b); else y=x-y,t=(double)y/(b-a);if((i nt)t==t)pri ntf("%d\n",(i nt)t); else prin tf("%lf\n",t);}else { if(a>b)y=y-x,t=(double)y/(a-b); else y=L-y+x,t=(double)y/(b-a); if((i nt)t==t)pri ntf("%d\n",(i nt)t); else prin tf("%lf\n",t);}return 0;}#i nclude<stdio.h>int _max(i nt a,i nt b){ _retur n a>b?a:b;}int a[20];int f[20][20];int main(){int n ,i,j,s=0;sca nf("%d",&n);for(i=0;i< n;i++)scan f("%d",&a[i]);for(j=1;j< n;j++)f[0][0]=a[0],f[0][j]=f[0][j-1]*a[j]; for(i=1;i< n;i++){f[i][i-1]=1;for(j=i;j< n;j++)f[i][j]=f[i][j-1]*a[j];}for(i=0;i< n;i++) for(j=i;j< n;j++) s=_max(s,f[i][j]);if(s==O)pri ntf("-1\n"); else prin tf("%d\n",s); return 0;}#i nclude<stdio.h>int main(){int x=192,y, z,a,b,c,d,e,f,g,h,i;for(;x<328;x++){y=2*x;z=3*x;a=x/100%10;b=x/10%10;c=x%10;d=y/100%10;e=y/10%10;f=y%10;g=z/100%10;h=z/10%10;i=z%10;if(a==b||a==c||a==d||a==e||a==f||a==g||a==h||a==i||a==0) con ti nue;if(b==c||b==d||b==e||b==f||b==g||b==h||b==i||b==0) con ti nue;if(c==d||c==e||c==f||c==g||c==h||c==i||c==0) con ti nue;if(d==e||d==f||d==g||d==h||d==i||d==0) con ti nue;if(e==f||e==g||e==h||e==i||e==O) con ti nue; if(f==g||f==h||f==i||f==O) con ti nue; if(g==h||g==i||g==O) con ti nue; if(h==i||h==O) continue;prin tf("%d %d %d\n",x,y,z);}return 0;}#i nclude<stdio.h>int main(){int a,b,c,sum=10;sca nf("%d%d%d",&a,&b,&c);for(;sum<=100;sum++){if(sum%3==a&&sum%5==b&&sum%7==c){ prin tf("%d\n",sum); break;}}if(sum==101)pri ntf("-1\n");return 0;}輸出合敎世圮起始导殆束年檢,用空恪隔开#i nclude<stdio.h>#in clude<math.h>int main(){int ce,y,m, n,a=0;sca nf("%d",&n); for(ce=0;;ce+=100){for(y=ce+1;y<ce+100;y+=2){ for(m=3;m<sqrt(y);m+=2){ if(y%m==0) break;}if(m>=sqrt(y)) break;}if(y==ce+101) a++;if(a==n) break;}prin tf("%d %d\n",ce,ce+99); return 0;}{int n,i;sca nf("%d",&n);for(i=1;i<=n ;i++){if(i%7==0) pri ntf("%d ",i);else if(i/1000%10==7||i/100%10==7||i/10%10==7||i%10==7) printf("%d ",i ); }return 0;}#i nclude<stdio.h>double a[100000000];int main(){int n,i;double ave,sum=0;sca nf("%d",&n);for(i=0;i< n;i++){scan f("%lf",&a[i]); sum=sum+a[i];}ave=su m/n;for(i=0,sum=0;i <n ;i++) sum=sum+(a[i]-ave)*(a[i]-ave); prin tf("%lf\n",sum); return 0;}int f[100000000];int main(){int n,i;sca nf("%d",&n);for(i=0;i< n;i++){int a,b;scan f("%d%d",&a,&b);f[i]=a+b;}for(i=0;i< n;i++){if(f[i]>100) f[i]=f[i]/10%10*10+f[i]%10,pri ntf("%d\n",f[i]); else prin tf("%d\n",f[i]); }return 0;}ttinc-udeAsfdio.hvttinc-udeAmafh.hvinfn H n v v k t八「efumn QO —k八inf main。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

圆及圆球等的相关计算计算成绩
找最大数
找幸运数
#include <iostream> using namespace std; int main()
{
int A,B,c;
cin>>A>>B;
c=A+B;
cout<<c<<endl;
return 0;
}
圆及圆球等的相关计算
#include <iostream>
#include <iomanip>
using namespace std;
#define PI 3.1416
int main()
{
double r,h,l,s,sq,vq,vz;
cin>>r>>h;
l=2*PI*r;
s=PI*r*r;
sq=4*PI*r*r;
vq=4*PI*r*r*r/3;
vz=s*h;
cout<<fixed<<setprecision(2)<<l<<endl;
cout<<fixed<<setprecision(2)<<s<<endl;
cout<<fixed<<setprecision(2)<<sq<<endl;
cout<<fixed<<setprecision(2)<<vq<<endl;
cout<<fixed<<setprecision(2)<<vz<<endl;
return 0;
}
计算成绩
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double a,b,c,A,B;//定义数学成绩a,英语成绩b,c语言成绩c cin>>a>>b>>c;
A=a+b+c;
B=A/3.0;
cout<<fixed<<setprecision(6)<<A<<endl;
cout<<fixed<<setprecision(6)<<B<<endl;
return 0; }
找最大数
#include <iostream>
using namespace std;
int main()
{
int A,B,C;
cin>>A>>B>>C;
if(A>B && A>C) cout<<A<<endl;
else
if(B>A && B>C) cout<<B<<endl;
else cout<<C<<endl;
return 0;
}
找幸运数
#include <iostream>
using namespace std;
int main()
{
int m,n,a,b,c,d,e,f;
cin>>m;
a=m%10;
b=m/10%10;
c=m/100%10;
d=m/1000%10;
e=m/10000%10;
if(e==0) {
if(d==0) {
if(c==0){
if(b==0) {
if(a==0) {
n=0;
}
else {
n=a;
}
}
else {
n=a*10+b;
}
}
else {
n=a*100+b*10+c;
}
}
else {
n=a*1000+b*100+c*10+d;
}
}
else {
n=a*10000+b*1000+c*100+d*10+e;
}
if(m==n) cout<<"yes"<<endl;
else cout<<"no"<<endl;
return 0;
}
奖金发放
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double w,y;
cin>>w;
if(w<=10) y=0.1*w;
else if(w<=20) y=(w-10)*0.075+1;
else if(w<=40) y=(w-20)*0.05+1.75;
else if(w<=60) y=(w-40)*0.03+2.75;
else if(w<=100) y=(w-60)*0.015+3.35;
else y=(w-60)*0.01+3.95;
cout<<fixed<<setprecision(6)<<y<<endl;
return 0;
}
出租车费
难点:不足一公里按一公里收费。

【ceil函数】
法一【“%”取余的充分运用】
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double s,y;
int a,b,c;
cin>>s;
c=s;
a=s*10;
b=a%10;
if(s<=2) y=7;
else if(s<=15) {
if(b==0) y=7+1.5*(s-2);
else y=7+1.5*(c-1);
}
else {
if(b==0) y=26.5+2.1*(s-15);
else y=26.5+2.1*(c-14);
}
cout<<fixed<<setprecision(6)<<y<<endl;
return 0;
}
法二【ceil函数】#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
double s,y;
int a;
cin>>s;
a=ceil(s);
if(s<=2) y=7;
else if(s<=15) {
y=7+1.5*(a-2);
}
else {
y=26.5+2.1*(a-15);
}
cout<<fixed<<setprecision(6)<<y<<endl;
return 0;
}。

相关文档
最新文档