为什么这里只改变一个【关键词】或【语句位置】会导致结果错误,求解!!!
这个是正确的代码(gcc编译器、Dev-C++编译环境)
#include <stdio.h>/*Input:10move 9 onto 1move 8 over 1move 7 over 1move 6 over 1pile 8 over 6pile 8 over 5move 2 over 1move 4 over 9quit*/void moveAontoB( int a, int b ) { }void moveAoverB( int a, int b ) { }void pileAontoB( int a, int b ) { }void pileAoverB( int a, int b ) { }int main( ){ int n, i, j;//Read the value: n | P.s. [ 0, n - 1 ] | 1 <= n && n <= 24; i, j are for loop; scanf( "%d", &n ); char TempString[ 5 ]; short TempShort[ 2 ]; while( 1 ) { scanf( "%s", TempString ); //Keyword1: m(o)ve; p(i)le; q(u)it; //Keyword2: o(n)to; o(v)er; if( TempString[ 1 ] == 'o' ){//Judge it 1"move" scanf( "%d%s%d", &TempShort[ 0 ], TempString, &TempShort[ 1 ] ); printf( "%d %s %d\n", TempShort[ 0 ], TempString, TempShort[ 1 ] );//TEST if( TempString[ 1 ] == 'n' ) moveAontoB( TempShort[ 0 ], TempShort[ 1 ] );//Judge it 2"onto" else if( TempString[ 1 ] == 'v' ) moveAoverB( TempShort[ 0 ], TempShort[ 1 ] );//Judge it 2"over" else { } } else if( TempString[ 1 ] == 'i' ){//Judge it 1"pile" scanf( "%d%s%d", &TempShort[ 0 ], TempString, &TempShort[ 1 ] ); printf( "%d %s %d\n", TempShort[ 0 ], TempString, TempShort[ 1 ] );//TEST if( TempString[ 1 ] == 'n' ) pileAontoB( TempShort[ 0 ], TempShort[ 1 ] );//Judge it 2"onto" else if( TempString[ 1 ] == 'v' ) pileAoverB( TempShort[ 0 ], TempShort[ 1 ] );//Judge it 2"over" else { } } else if( TempString[ 1 ] == 'u' ) break;//Judge it 1"quit" else { } } //Output them for( i = 0; i < n; i ++ ) { printf( "%d:", i ); for( j = 0; j < 1; j ++ ) {} printf( "\n" ); } system( "PAUSE" );}#include <stdio.h>/*Input:10move 9 onto 1move 8 over 1move 7 over 1move 6 over 1pile 8 over 6pile 8 over 5move 2 over 1move 4 over 9quit*/void moveAontoB( int a, int b ) { }void moveAoverB( int a, int b ) { }void pileAontoB( int a, int b ) { }void pileAoverB( int a, int b ) { }int main( ){ short n, i, j;//Read the value: n | P.s. [ 0, n - 1 ] | 1 <= n && n <= 24; i, j are for loop; scanf( "%d", &n ); char TempString[ 5 ]; short TempShort[ 2 ]; while( 1 ) { scanf( "%s", TempString ); //Keyword1: m(o)ve; p(i)le; q(u)it; //Keyword2: o(n)to; o(v)er; if( TempString[ 1 ] == 'o' ){//Judge it 1"move" scanf( "%d%s%d", &TempShort[ 0 ], TempString, &TempShort[ 1 ] ); printf( "%d %s %d\n", TempShort[ 0 ], TempString, TempShort[ 1 ] );//TEST if( TempString[ 1 ] == 'n' ) moveAontoB( TempShort[ 0 ], TempShort[ 1 ] );//Judge it 2"onto" else if( TempString[ 1 ] == 'v' ) moveAoverB( TempShort[ 0 ], TempShort[ 1 ] );//Judge it 2"over" else { } } else if( TempString[ 1 ] == 'i' ){//Judge it 1"pile" scanf( "%d%s%d", &TempShort[ 0 ], TempString, &TempShort[ 1 ] ); printf( "%d %s %d\n", TempShort[ 0 ], TempString, TempShort[ 1 ] );//TEST if( TempString[ 1 ] == 'n' ) pileAontoB( TempShort[ 0 ], TempShort[ 1 ] );//Judge it 2"onto" else if( TempString[ 1 ] == 'v' ) pileAoverB( TempShort[ 0 ], TempShort[ 1 ] );//Judge it 2"over" else { } } else if( TempString[ 1 ] == 'u' ) break;//Judge it 1"quit" else { } } //Output them for( i = 0; i < n; i ++ ) { printf( "%d:", i ); for( j = 0; j < 1; j ++ ) {} printf( "\n" ); } system( "PAUSE" );}
#include <stdio.h>/*Input:10move 9 onto 1move 8 over 1move 7 over 1move 6 over 1pile 8 over 6pile 8 over 5move 2 over 1move 4 over 9quit*/void moveAontoB( int a, int b ) { }void moveAoverB( int a, int b ) { }void pileAontoB( int a, int b ) { }void pileAoverB( int a, int b ) { }int n, i, j;//Read the value: n | P.s. [ 0, n - 1 ] | 1 <= n && n <= 24; i, j are for loop;int main( ){ scanf( "%d", &n ); char TempString[ 5 ]; short TempShort[ 2 ]; while( 1 ) { scanf( "%s", TempString ); //Keyword1: m(o)ve; p(i)le; q(u)it; //Keyword2: o(n)to; o(v)er; if( TempString[ 1 ] == 'o' ){//Judge it 1"move" scanf( "%d%s%d", &TempShort[ 0 ], TempString, &TempShort[ 1 ] ); printf( "%d %s %d\n", TempShort[ 0 ], TempString, TempShort[ 1 ] );//TEST if( TempString[ 1 ] == 'n' ) moveAontoB( TempShort[ 0 ], TempShort[ 1 ] );//Judge it 2"onto" else if( TempString[ 1 ] == 'v' ) moveAoverB( TempShort[ 0 ], TempShort[ 1 ] );//Judge it 2"over" else { } } else if( TempString[ 1 ] == 'i' ){//Judge it 1"pile" scanf( "%d%s%d", &TempShort[ 0 ], TempString, &TempShort[ 1 ] ); printf( "%d %s %d\n", TempShort[ 0 ], TempString, TempShort[ 1 ] );//TEST if( TempString[ 1 ] == 'n' ) pileAontoB( TempShort[ 0 ], TempShort[ 1 ] );//Judge it 2"onto" else if( TempString[ 1 ] == 'v' ) pileAoverB( TempShort[ 0 ], TempShort[ 1 ] );//Judge it 2"over" else { } } else if( TempString[ 1 ] == 'u' ) break;//Judge it 1"quit" else { } } //Output them for( i = 0; i < n; i ++ ) { printf( "%d:", i ); for( j = 0; j < 1; j ++ ) {} printf( "\n" ); } system( "PAUSE" );}