1007

来源:互联网 发布:剪辑音频的软件 编辑:程序博客网 时间:2024/05/17 03:47
如果仅仅尝试用字符数组中元素保存逆序数会提示<span style="color: rgb(255, 0, 0); font-family: 'Times New Roman', Times, serif;font-size:14px; text-align: -webkit-center;">Runtime Error 。另外设数组变量存储逆序数则A。</span>
A:
#include<stdio.h>#include<math.h>#include<string.h>int orderV[100];int order = 0;void com( char p[52] ){int length1 = strlen(p);int j,k;int count =  0;for( j = 0;j <= length1 - 2;j++ ){for( k = j+1;k <= length1 -1;k++ ){if( p[j] > p[k] ){count++;}}}orderV[order++] = count;}int main(){int n,m,i,j;char a[100][52];scanf("%d%d",&n,&m);for( i=0;i <= m-1;i++ ){scanf("%s",&a[i]);com( a[i] );}for( i = 0;i <= m - 1;i++){for( j = 0;j <= m - 2 - i;j++ ){if( orderV[j] > orderV[j+1] ){char temp[51];strcpy(temp,a[j]);strcpy(a[j],a[j+1]);strcpy(a[j+1],temp);int tempInt = orderV[j];orderV[j] = orderV[j+1];orderV[j+1] = tempInt;}}}for( i = 0;i <= m-1;i++ ){puts(a[i]);}return 0;}
<span style="color: rgb(255, 0, 0); font-family: 'Times New Roman', Times, serif;font-size:14px; text-align: -webkit-center;">Runtime Error:</span>
<span style="color: rgb(255, 0, 0); font-family: 'Times New Roman', Times, serif;font-size:14px; text-align: -webkit-center;">#include<stdio.h>#include<math.h>#include<string.h>void com( char p[52] ){<span style="white-space:pre"></span>int length1 = strlen(p);<span style="white-space:pre"></span>int j,k;<span style="white-space:pre"></span>int count =  0;<span style="white-space:pre"></span>for( j = 0;j <= length1 - 2;j++ ){<span style="white-space:pre"></span>for( k = j+1;k <= length1 -1;k++ ){<span style="white-space:pre"></span>if( p[j] > p[k] ){<span style="white-space:pre"></span>count++;<span style="white-space:pre"></span>}<span style="white-space:pre"></span>}<span style="white-space:pre"></span>}<span style="white-space:pre"></span>p[length1] = count + '0';}int main(){<span style="white-space:pre"></span>int n,m,i,j;<span style="white-space:pre"></span>char a[100][52];<span style="white-space:pre"></span>scanf("%d%d",&n,&m);<span style="white-space:pre"></span>for( i=0;i <= m-1;i++ ){<span style="white-space:pre"></span>scanf("%s",&a[i]);<span style="white-space:pre"></span>com( a[i] );<span style="white-space:pre"></span>}<span style="white-space:pre"></span>for( i = 0;i <= m - 1;i++){<span style="white-space:pre"></span>for( j = 0;j <= m - 2 - i;j++ ){<span style="white-space:pre"></span>if( a[j][n] > a[j+1][n] ){<span style="white-space:pre"></span>char temp[51];<span style="white-space:pre"></span>strcpy(temp,a[j]);<span style="white-space:pre"></span>strcpy(a[j],a[j+1]);<span style="white-space:pre"></span>strcpy(a[j+1],temp);<span style="white-space:pre"></span>}<span style="white-space:pre"></span>}<span style="white-space:pre"></span>}<span style="white-space:pre"></span>for( i = 0;i <= m-1;i++ ){<span style="white-space:pre"></span>for( j = 0;j <= n - 1;j++ ){<span style="white-space:pre"></span>putchar(a[i][j]);<span style="white-space:pre"></span>}<span style="white-space:pre"></span>putchar('\n');<span style="white-space:pre"></span>}<span style="white-space:pre"></span><span style="white-space:pre"></span>return 0;}</span>

0 0