问题 问答题

函数ReadDat()实现从文件in.dat中读取一篇英文文章并存入到字符串数组xx中,请编制函数sortcharD(),其函数的功能是以行为单位对字符按从小到大的顺序进行排序,排序后的结果仍按行重新存入字符串数组中,最后调用函数writeDat(),把结果xx输出到文件out.dat中。
例:原文:dAeBfC.
结果:ABCdef.
原数据文件存放的格式是每行的宽度均小于80个字符,含标点符号和空格。
注意:部分源程序给出如下:
请勿改动主函数main()、读数据函数ReadDat()和输出数据函数writeDat()的内容。
[试题源程序]
#include<stdio.h>
#include<strinq.h>
#include<conio.h>
char xx([50][80];
int maxline=0; /*文章的总行数*/
int ReadDat(void);
void WriteDat(void);
void SortCharD(void)


int ReadDat(void)

FILE*fp;
int i=0;
char*P;
if((fp=fopen("IN.DAT","r"))==NULL)return 1:
while(fgets(xx[i],80,fp)!=NULL)

P=strchr(xx[i],’n’);
if(p)*P=0:
i++:

maxline=i;
fclose(fp);
return 0;

void WriteDat(void)

FILE*fp;
int i;
fp=fopen("OUT.DAT","w");
for(i=0;i<maxline;i++)

printf("%s\n",xx[i]);
fprintf(fp,"%s\n",xx[i]);

fclose(fp);

void main()

system("cls");
if(ReadDat())

printf("数据文件IN.DAT不能打开!\n\007");
return;

SortCharD();
WriteDat():

答案

参考答案:void SortCharD(void)
{
int i,j,k,str;
char ch;
for(i=0;i<maxline;i++) /*遍历所有行*/
{
str=strlen(xx[i]);
for(J=0:J<str-1;J++)
for(k=J+1;k<str;k++) /*对每行元素进行选择排序*/
if(xx[i][j]>xx[i][k])
{ /*如果存在顺序,交换两个元素*/
ch=xx[i][j];
xx[i][j]=xx[i][k];
xx[i][[k]=ch;
}
}
}

解析: 本题主要考查的是字符串排序问题。首先用for循环和变量i对每一行遍历,对于某一行xx[i]来说,使用两重for循环进行冒泡排序。对某一个字符xx[i][j]来说,将该字符后面的每个字符xx[i][k](k从j+1开始)和xx[[i][J]进行比较,如果存在顺序则使用临时变量ch,将xx[i][j]和xx[i][k]交换位置。

单项选择题 共用题干题
填空题

Monday’s Supreme Court decision to block a class-action sex-discrimination lawsuit against Wal-Mart was a huge setback for as many as 1.6 million current and former female employees of the world’s largest retailer. But the decision has consequences that range far beyond sex discrimination or the viability of class-action suits.

The underlying issue, which the Supreme Court has now ratified, is Wal-Mart’s authoritarian style, by which executives pressure store-level management to squeeze more and more from millions of clerks, stockers and lower-tier managers.

(41) ______.

In the 1950s and ’60s, northwest Arkansas, where Wal-Mart got its start, was poor, white and rural, in the midst of a wave of agricultural mechanization that generated a huge surplus of unskilled workers. To these men and women, the burgeoning chain of discount stores founded by Sam Walton was a godsend. The men might find dignity managing a store instead of a hardscrabble farm, while their wives and daughters could earn pin money clerking for Mr. Sam. "The enthusiasm of Wal-Mart associates toward their jobs is one of the company’s greatest assets," declared the firm’s 1973 annual report.

(42) ______.

Wal-Mart attorneys have argued, and the Supreme Court agreed this week, that even if sex discrimination was once part of the company’s culture, it is now ancient history: if any store managers are guilty of bias when it comes to promoting women, they are at odds with corporate policy. Wal-Mart is no longer an Ozark company; it is a cosmopolitan, multinational operation.

But that avoids the more essential point, namely that Wal-Mart views low labor costs and a high degree of workplace flexibility as a signal competitive advantage. It is a militantly anti-union company that has been forced to pay hundreds of millions of dollars to current and former employees for violations of state wage and hour laws.

There are tens of thousands of experienced Wal-Mart women who would like to be promoted to the first managerial rung, salaried assistant store manager. (43) ______.

Why Because, for all the change that has swept over the company, at the store level there is still a fair amount of the old communal sociability. Recognizing that workers steeped in that culture make poor candidates for assistant managers, who are the front lines in enforcing labor discipline, Wal-Mart insists that almost all workers promoted to the managerial ranks move to a new store, often hundreds of miles away. (44) ______.

(45) ______. Not unexpectedly, some managers think women with family responsibilities would balk at such demands.

For a time it seemed as if the class-action lawsuit might be a partial substitute for the role of union. By drastically limiting how a class-action suit can be brought, the Supreme Court leaves millions of service-sector workers with few avenues to escape the grinding work life and limited opportunities that so many now face.

[A] But Wal-Mart makes it impossible for many of them to take that post, because its ruthless management style structures the job itself as one that most women, and especially those with young children or a relative to care for, would find difficult to accept.

[B] The obstacles to women’s advancement do not stop there. The workweek for salaried managers is around 50 hours or more, which can surge to 80 or 90 hours a week during holiday seasons.

[C] Indeed. the sex discrimination at Wal-Mart that drove the recent suit is the product not merely of managerial bias and prejudice, but also of a corporate culture and business model that sustains it, rooted in the company’s very beginnings.

[D] Especially in recent years, Wal-Mart’s same-store sales have declined. Workers of both sexes pay the price, but women, who constitute more than 70 percent of hourly employees, pay more.

[E] A patriarchal (男性统治或者主宰的) ethos was written into the Wal-Mart DNA. And that corporate culture was "the single most important element in the continued, remarkable success of Wal-Mart," asserted Don Soderquist, the company’s chief operating officer in the 1990s.

[F] There used to be a remedy for this sort of managerial authoritarianism: it was called a union, which bargained over not only wages and pensions but also the kind of qualitative issues, including promotion and transfer policies.

[G] For middle-aged women caring for families, this corporate reassignment policy amounts to sex discrimination. True, Wal-Mart is hardly alone in demanding that rising managers sacrifice family life, but few companies make relocation such a fixed policy.

43()