Title: 7-2 count the number of words in a line of text 1. PTA Submission List
2. Design Ideas
定义变量a[1000]储存文本出现的单词变量i用于循环,变量m表示字符串长度,变量k表示单词个数;if a[0] != 空格 则k=0;反之 k=1;for i=0 to i<m-1 if a[i]==空格并且a[i+1] != 空格 则k++输出k
3. Code (note,,,. Do not paste on the blog. No need to use ... syntax to render)
4. Problems encountered in debugging process and PTA Submission List situation description.
(each error in the PTA submission list explains why and how to resolve it.) )
Write this problem, think of using a[i]!= space and a[i+1] = = space, but the last character is not a space, always cause a small number of output I
Workaround: First by a condition to determine whether a[0] is equal to the space to give a value of k, so that you can consider the case of only one word, can also make the result is correct.
Title: 7-5 Statistic Capital consonant letter 1. PTA Submission List
2. Design Ideas
3. Code (note,,,. Do not paste on the blog. No need to use ... syntax to render)
4. Problems encountered in debugging process and PTA Submission List situation description.
(each error in the PTA submission list explains why and how to resolve it.) )
The problem is not met.
Title: 7-1 string converted to decimal integer 1. PTA Submission List
2. Design Ideas
int i=0,k=0; 循环变量 char hexad[80],str[80]; 数组str用于储存输入的字符串,数组hexad为数组str滤去非十六进制后生成新字符串 long number=0,flag=1; 输入字符串str[i],将‘\0‘存入数组,遇见#停止 for i=0 如果str[i]!=‘\0‘ 则i++) 如果 str[i]==‘-‘并且k==0 则flag=-1; //存在‘-‘情况 如果 str[i]>=‘0‘&&str[i]<=‘9‘||str[i]>=‘a‘&&str[i]<=‘f‘||str[i]>=‘A‘&&str[i]<=‘F‘ 滤去非十六进制后生成新字符串hexad hexad[k]=str[i]; k++; hexad[k]=‘\0‘; for i=0 如果hexad[i]!=‘\0‘ 则i++ 转化成十进制 如果 hexad[i]>=‘0‘&&hexad[i]<=‘9‘ 计算number=number*16+hexad[i]-‘0‘; 如果hexad[i]>=‘a‘&&hexad[i]<=‘f‘ 计算number=number*16+hexad[i]-‘a‘+10; 如果hexad[i]>=‘A‘&&hexad[i]<=‘F‘ 计算number=number*16+hexad[i]-‘A‘+10; 输出number*flag
3. Code (note,,,. Do not paste on the blog. No need to use ... syntax to render)
4. Problems encountered in debugging process and PTA Submission List situation description.
(each error in the PTA submission list explains why and how to resolve it.) )
does not consider the '-' existence situation, causing the code to be part of the correct
Workaround: Define a flag representation symbol, consider the presence of a minus sign, convert the symbol using the flag
Second, this week's topic set PTA Final ranking. (2 points)
PTA Rankings
Third, peer code peer review (1 points) 1. Mutual evaluation of the name of the student tube is 2. My code, peer-to-peer code (here the core code is good, not necessarily all the code, the figure indicates whose code.) )
Yu Zheng's Code
My Code
3. Where do I differ from my classmates ' code? What are the advantages? What style of code do you prefer? If the classmate code is wrong, please help to point out where the problem.
(Note: The 3rd item is the scoring focus, must be targeted to say the problem, do not say good words, please professional to tell what the advantages of his code, which disadvantages. )
The code for the two of us to generate a new string after the input of the string and the hexad of the non-hexadecimal is basically the same, but there is a huge difference in considering '-' existence. The tube is exactly where the number is calculated, by judging a[i]== '-', a[i+1] to 16 characters, assign the '-' to OP, and use the variable time to ensure that '-' is the beginning, without the presence of the middle. And I use the process of filtering non-hexadecimal, by judging str[i]== '-' and k==0, the symbol is defined. That's why my code steps are small, and his steps are quite varied. Although many of his steps are essential, they are superfluous. Why is it necessary, because if the time++ in his three-case calculations are removed, or if the time==1 in the judgment of array A is removed, it will result in an error. Said his code was superfluous because he could have used so many variables to define a symbol, and his final output would have to be judged by x=1 and then output separately. So I like my code more. As for the problem with our code, I also realize that the same PTA problem, even if the previous code steps are consistent, but as long as a different step, the code will be very different. And the difficulty of the code is sometimes a step in the gap.
Iv. Summary of this week's study (3 points)
1. What have you learned?
1.1 How pointer variables are defined (design code can be rendered with markdown code symbols)?
Variable name of type variable
int p;
Char *p;
1.2 pointer addition operation in which case, can the 2 pointer variables be added to each other?
When the pointer points to an array, increments indicate that the pointer moves down;
1.3 The pointer does not assign the initial value, direct use, what happens, please use DEVC verification, and show?
Random numbers appear
1.4 Lessons about separating the integer and fractional parts of a floating-point number, use DEVC to verify the implementation, and show it in this map, and also indicate which is the pointer variable to do the function parameter, and how the function argument should be represented. What is the use of pointer variables for function parameters?
Pointer variable do function parameter void spllitfloat (float x,int* intpart,float* fracpart)
function argument spllitfloat (X,IP,FP);
You can change the value of a variable in the main function in a function
1.5 Please change the bubble sort function of the textbook into a pointer variable to do the formal parameter format, and write the code at the bottom, pay attention to the markdown syntax rendering.
void bubble(int *p,int n){ int i,j,t; for(i=1;i<n;i++) for(j=0;j<n-i;j++,p++) if(*p>*(p+1)) { t=*p; *p=*(p+1); *(p+1)=t; }}
1.6 How to define a pointer variable to an array, and how to use a pointer variable to represent an array element?
Assigning an array name to a pointer variable name
int p;
int a[5];
P=a;
1.7 How do I define a character pointer to a string? Where is the initial position after the pointer points to the string?
Char P,STR[11]={YJSYJSYJSNB};
P=STR;
Initial position is str[0]
1.8 Use a character pointer to manipulate strings, such as design functions, to implement string joins, and show the code in this map. What are the advantages of the method that indicates the pointer represents a character?
More flexible and shorter.
2. What is your content this week?
2.1 Class allocation and how to revise the wrong questions.
This problem is wrong, it should be said that the problem and the pointer does not have much to do with the priority of the operation symbol, I should first determine whether P1==&M is set up to 1, is not established as 0;
Address constants cannot be changed
A value of 10,c exceeds the value of 9,d and cannot be added, so it is B;
A character variable cannot be assigned a value
2.2 Others not? How are we going to solve
Read, Baidu, ask classmates
3. The test summary of the array on the machine
3.1 The wrong question, please list?
function second question, array all questions
3.2 Wrong question How to revise, why wrong?
IP Address
#include<stdio.h>int main(){ char ch[33]; int i=0,sum=0,count=0,time=0; scanf("%c",&ch[i]); while(ch[i]!=‘\n‘){ i++; scanf("%c",&ch[i]); } for(i=0;i<32;i++){ sum=sum*2+ch[i]-‘0‘; count++; if(count%8==0){ time++; if(time==1) { printf("%d",sum); } else{ printf(".%d",sum); } sum=0; } } return 0;}
No other questions, no ideas.
C Language Blog Job--character array