You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <stdio.h>
# include <string.h>
# include <malloc.h>
# include <stdlib.h>
# include <conio.h>
typedef struct pot
{
char gh [ 10 ] ;
int num ;
struct pot * next ;
} pot ;
int x ;
int leiji ( pot * pnew , pot * head , int x )
{
pot * p = head - > next ;
while ( p - > next ! = NULL ) {
if ( strcmp ( pnew - > gh , p - > gh ) = = 0 ) {
p - > num = p - > num + pnew - > num ;
x = 1 ;
break ;
}
p = p - > next ;
}
return x ;
}
pot * input ( void )
{
pot * phead , * ptail ;
phead = ( pot * ) malloc ( sizeof ( pot ) ) ;
if ( phead = = NULL ) {
printf ( " 链表创建失败 " ) ;
exit ( - 1 ) ;
}
ptail = phead ;
ptail - > next = NULL ;
while ( 1 ) {
int t = 0 ;
x = 0 ;
pot * pnew ;
pnew = ( pot * ) malloc ( sizeof ( pot ) ) ;
if ( pnew = = NULL ) {
printf ( " 节点申请失败 " ) ;
exit ( - 1 ) ;
}
printf ( " \n " ) ;
scanf ( " %s %d " , pnew - > gh , & pnew - > num ) ;
ptail - > next = pnew ;
pnew - > next = NULL ;
x = leiji ( pnew , phead , x ) ;
if ( x )
{
printf ( " 您输入的工号之前已输入过,产品数已自动帮您累计在之前的职工 \n " ) ;
ptail - > next = NULL ;
t = 1 ;
goto loop ;
continue ;
}
ptail = pnew ;
printf ( " \n 按1继续***按0结束 " ) ;
loop : if ( t )
{
printf ( " \n 按1继续***按0结束 " ) ;
}
char ch ;
ch = getch ( ) ;
if ( ch = = ' 1 ' )
continue ;
else if ( ch = = ' 0 ' )
break ;
else {
printf ( " \n 您的输入非0且非1, 请重新选择 \n " ) ;
t = 1 ;
goto loop ;
}
}
return phead ;
}
void sortlistgh ( pot * head )
{
pot * i , * j ;
char tgh [ 10 ] ;
int tnum ;
for ( i = head - > next ; i - > next ! = NULL ; i = i - > next ) {
for ( j = head - > next ; j - > next ! = NULL ; j = j - > next ) {
if ( strcmp ( j - > gh , j - > next - > gh ) > 0 ) {
strcpy ( tgh , j - > gh ) ;
strcpy ( j - > gh , j - > next - > gh ) ;
strcpy ( j - > next - > gh , tgh ) ;
tnum = j - > num ;
j - > num = j - > next - > num ;
j - > next - > num = tnum ;
}
}
}
}
void sortlistnum ( pot * head )
{
pot * i , * j ;
char tgh [ 10 ] ;
int tnum ;
for ( i = head - > next ; i - > next ! = NULL ; i = i - > next ) {
for ( j = head - > next ; j - > next ! = NULL ; j = j - > next ) {
if ( j - > num < j - > next - > num ) {
strcpy ( tgh , j - > gh ) ;
strcpy ( j - > gh , j - > next - > gh ) ;
strcpy ( j - > next - > gh , tgh ) ;
tnum = j - > num ;
j - > num = j - > next - > num ;
j - > next - > num = tnum ;
}
}
}
}
void printlist ( pot * phead )
{
int i = 1 ;
printf ( " \n " ) ;
printf ( " | 名次 | 完成产品数 | 职工工号 | \n " ) ;
pot * p ;
p = phead - > next ;
while ( p ! = NULL ) {
printf ( " %d " , i + + ) ;
printf ( " %d %s " , p - > num , p - > gh ) ;
while ( p - > next ! = NULL & & p - > next - > num = = p - > num ) {
p = p - > next ;
printf ( " |%s " , p - > gh ) ;
}
printf ( " \n " ) ;
if ( p - > num ! = p - > next - > num ) ;
p = p - > next ;
}
}
int main ( )
{
printf ( " *********职工工作量统计系统********* \n " ) ;
printf ( " 请输入职工工号与完成产品数; \n " ) ;
pot * head = input ( ) ;
sortlistgh ( head ) ;
sortlistnum ( head ) ;
printlist ( head ) ;
return 0 ;
}