0 of 2 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 2 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
1、阅读程序,根据输入写出输出:
1 2 3 4 5 6 7 8 9 10 |
#include <iostream> using namespace std; int main (){ char c; do { c=getchar(); cout<<c; } while (c != '.'); return0; } |
读上面程序,如果输入为”hello. world!”,输出结果为
2、阅读下面程序,根据输入写出输出结果: (2007年真题)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include "ctype.h" #include "stdio.h" void expand( char s1[], char s2[] ) { int i, j, a, b, c; j = 0; for ( i = 0; (c = s1[i]) != '\0'; i++ ) if ( c == '-' ) { a = s1[i - 1]; b = s1[i + 1]; if ( isalpha( a ) && isalpha( b ) || isdigit( a ) && isdigit( b ) ) /*函数 isalpha(a) 用于判断字符 a 是否为字母,*/ /*函数 isdigit(b) 用于判断字符 b 是否为数字,如果是,返回 1,否则返回 0 */ { j--; do s2[j++] = a++; while ( tolower( a ) < tolower( s1[i + 1] ) ); } /*函数 tolower(a) 的功能是当字符 a 是大写字母,改为小写,其余情况不变*/ else s2[j++] = c; }else s2[j++] = c; s2[j] = '\0'; } int main() { char s1[100], s2[300]; printf( "input s1:" ); gets( s1 ); //gets函数功能为读入整行字符串s1 expand( s1, s2 ); printf( "%s\n", s2 ); } |
程序输入为:wer2345d-h454-82qqq
程序输出为: