String Output Processing
String Output Processing
I have a headache with the output of strings, that is, I cannot grasp the skills well. I remember that when I first came into contact with strings, I was about to lose the input ...... No. I just cannot find the skills. I will analyze these questions from simple to complex, which may not be complete. Please forgive me.
I.
To start with the question, just enter a sentence like "hello my friend". The output is "dneirf ym olleh". You can see that there is nothing, that is, you are entering the text and outputting it backwards, let's take a look at the main code content.
#include
#include
int main(){int i, len;char a[1000];while(gets(a)){len=strlen(a);for(i=len-1;i>=0;i--){printf("%c", a[i]);}printf("\n");}return 0;}
Simply put, it is "input, output". Note that there are spaces in this sentence. Therefore, use gets (), scanf () the feature is that it will stop when you encounter spaces or press Enter. You can try it to help deepen your impression.
II.
The general meaning is to enter a sentence casually, for example, "hello my friend". The output is "olleh ym dneirf". What do you see, that is, the position of each word is still the original position, but the output is reversed. The following is an example.
Word Reversal
Description
For each list of words, output a line with each word reversed without changing the order of the words.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. each input block is in the format indicated in the problem description. there is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Input
You will be given a number of test cases. the first line contains a positive integer indicating the number of cases to follow. each case is given on a line containing a list of words separated by one space, and each word contains only uppercase and lowercase letters.
Output
For each test case, print the output on one line.
Sample Input
1
3
I am happy today
To be or not to be
I want to win the practice contest
Sample Output
I ma yppa yadot
OT eb ro ton ot eb
I tnaw ot niw eht ecitcarp tsetnoc
Let's take a look at my code.
# Include
# Include
Int main () {int n, I, len, j, l, m, k; char a [100]; while (~ Scanf ("% d", & m) {for (k = 0; k
The idea of this question is that output should be carried out in front of a space, and the last word should be paid special attention, so that we know that special processing is required.
Another question type is taken into account in upper case. In the future, it will be explained in detail that it is not easy to control the string well. So come on!