1009. Speak the opposite language. 1009. Speak the opposite language.
1 /*
2 * Main.c
3 * 1009. To speak back
4 * Created on: August 29, 2014
5 *
6 ********** Test passed ******
7 * /
8
9 #include <stdio.h>
10 #include <string.h>
11
12 char inStr [81];
13 char outStr [41] [81];
14
15 int main (void) {
16
17 int i, j;
18 int wordNum = 0;
19
20 gets (inStr);
twenty one
22 int length = strlen (inStr);
23 // Separated by spaces, store each word into a two-dimensional array
24 j = 0;
25 for (i = 0; i <length; i ++) {
26 if ('' == inStr [i]) {
27 wordNum ++;
28 j = 0;
29 continue;
30}
31 outStr [wordNum] [j ++] = inStr [i];
32}
33
34 while (wordNum> 0)
35 printf ("% s", outStr [wordNum--]);
36 printf ("% s \ n", outStr [0]);
37
38 return 0;
39}
This topic encountered a strange problem:
1 char inStr [81];
2 char outStr [41] [81];
When it is defined as global, it can run normally in my IDE; if it is defined as local (the position of the first line in main ()), the result will be garbled.
1. Visual Studio 2013 Express, local variables:
2. Ecplise Luna, MinGW, GCC, local variables:
But the strange thing is that the results of submitting PAT are correct, whether local or global, all passed. I don't understand it here, I hope you can give me advice! thank!
Title link:
http://pat.zju.edu.cn/contests/pat-b-practise/1009
reference:
http://www.xuebuyuan.com/1560821.html
1009 Talking back (20) Runs normally on VC ++, runtime error appears on the evaluation system
#include <stdio.h> int main () {char input [81]; int space [82]; int i, j = 0, a, k; int x; gets (input); input [80] = 0; // safe donespace [j ++] = -1; // mark the first word begin's frontfor (i = 0, x = 0; input [i]> 0; i ++, x ++) {if (input [i] == '' ) space [j ++] = i;} space [j] = x; // mark the last word endfor (a = j; a> 0; a-) {for (k = space [a-1] +1; k <space [a]; k ++) printf ("% c", input [k]); if (a> 1) printf (""); else printf ("\ n"); // the last not have blank } return (0);} Try this. Your code is too redundant.
Do women like to talk back?
Is n’t it ironic? It ’s arrogant. It ’s like coquetry. It ’s like your girlfriend is mad at you. You want to hug her. She will say get away. Who wants you to hold something like that?
Although it ’s almost the same as talking back, but there is a difference.
It ’s not necessary to say the opposite
Generally speaking, arrogance counts as a commendatory word