题目要求:
输入参数:参数A,含有任意个数的?的数值字符串,如:12?4,?代表一位任意数
参数B,不含?的数值字符串,长度与参数A一致
输出结果:参数A比参数B大的可能数值个数
输入样例
36?1?8
236428
8?3
910
?
5
输出样例
100
0
4
- #define num_max_length 20
- int main(void)
- {
- char num1[num_max_length];
- char num2[num_max_length];
- int result_temp=0, result=0;
- int num_length=0, num_index=0;
- int flag=0;
- while(1){
- memset(num1, 0, num_max_length);
- memset(num2, 0, num_max_length);
- result_temp=0;
- result = 0;
- flag = 0;
- printf("参数A:");
- fgets(num1, num_max_length, stdin);
- if(memcmp(num1, "end", 3)==0) break;
- printf("参数B:");
- fgets(num2, num_max_length, stdin);
- if(memcmp(num2, "end", 3)==0) break;
- if((num_length=strlen(num1))!=strlen(num2)){
- printf("num1 num2 length not match ");
- break;
- }
- for(num_index=0; num_index<num_length; num_index++){
- if(num1[num_index]=='?'){
- if(flag == 0)
- result_temp = (int)('9'-num2[num_index])+result_temp*10;
- else
- result_temp = result_temp*10;
- }
- else{
- if(num1[num_index]==num2[num_index]){
- continue;
- }
- else if(num1[num_index]<num2[num_index]){
- //break;
- if(flag == 0){
- flag = 1;
- }
- }
- else{
- if(flag == 0){
- flag = 1;
- result_temp += 1;
- }
- }
- }
- }
- printf("参数A比参数B大有%d种可能 ", result_temp);
- }
- printf("用户终止程序 ");
- system("pause");
- return 0;
- }