fork(6) download
  1. #include<stdio.h>
  2.  
  3. typedef struct Info{
  4. int ctrl,bank,digits[4];
  5. }Info;
  6.  
  7. void print(int num,int total){
  8. int digit = 0,temp = num;
  9.  
  10. while(temp != 0){
  11. temp /= 10;
  12. digit++;
  13. }
  14.  
  15. int i;
  16. for(i = 1;i <= (total - digit);i++)
  17. printf("0");
  18.  
  19. printf("%d",num);
  20. }
  21.  
  22. int compare(const void* A,const void* B){
  23. Info a = *(Info*)A,b = *(Info*)B;
  24.  
  25. if(a.ctrl != b.ctrl)
  26. return(a.ctrl - b.ctrl);
  27.  
  28. if(a.bank != b.bank)
  29. return(a.bank - b.bank);
  30.  
  31. if(a.digits[0] != b.digits[0])
  32. return(a.digits[0] - b.digits[0]);
  33.  
  34. if(a.digits[1] != b.digits[1])
  35. return(a.digits[1] - b.digits[1]);
  36.  
  37. if(a.digits[2] != b.digits[2])
  38. return(a.digits[2] - b.digits[2]);
  39.  
  40. return(a.digits[3] - b.digits[3]);
  41. }
  42. Info account[100000];
  43. int main(){
  44. int t;
  45. scanf("%d",&t);
  46.  
  47. while(t--){
  48. int n,i;
  49. scanf("%d",&n);
  50.  
  51. for(i = 0;i < n;i++)
  52. scanf("%d%d%d%d%d%d",&account[i].ctrl,&account[i].bank,&account[i].digits[0],&account[i].digits[1],&account[i].digits[2],&account[i].digits[3]);
  53. qsort(account,n,sizeof(account[0]),compare);
  54.  
  55. Info temp = account[0];
  56. int count = 1;
  57.  
  58. for(i = 1;i < n;i++){
  59. if(temp.ctrl == account[i].ctrl && temp.bank == account[i].bank && temp.digits[0] == account[i].digits[0] && temp.digits[1] == account[i].digits[1] && temp.digits[2] == account[i].digits[2] && temp.digits[3] == account[i].digits[3]){
  60. count++;
  61. }
  62. else{
  63. print(temp.ctrl,2);printf(" ");print(temp.bank,8);printf(" ");print(temp.digits[0],4);printf(" ");
  64. print(temp.digits[1],4);printf(" ");print(temp.digits[2],4);printf(" ");print(temp.digits[3],4);printf(" ");
  65. printf("%d\n",count);
  66. count = 1;
  67. temp = account[i];
  68. }
  69. }
  70.  
  71. print(temp.ctrl,2);printf(" ");print(temp.bank,8);printf(" ");print(temp.digits[0],4);printf(" ");
  72. print(temp.digits[1],4);printf(" ");print(temp.digits[2],4);printf(" ");print(temp.digits[3],4);printf(" ");
  73. printf("%d",count);
  74.  
  75. if(t != 0)
  76. printf("\n\n");
  77. }
  78.  
  79. return 0;
  80. }
  81.  
Success #stdin #stdout 0s 4640KB
stdin
2
6
03 10103538 2222 1233 6160 0142 
03 10103538 2222 1233 6160 0141 
30 10103538 2222 1233 6160 0141 
30 10103538 2222 1233 6160 0142 
30 10103538 2222 1233 6160 0141 
30 10103538 2222 1233 6160 0142 

5
30 10103538 2222 1233 6160 0144 
30 10103538 2222 1233 6160 0142 
30 10103538 2222 1233 6160 0145 
30 10103538 2222 1233 6160 0146 
30 10103538 2222 1233 6160 0143 
stdout
03 10103538 2222 1233 6160 0141 1
03 10103538 2222 1233 6160 0142 1
30 10103538 2222 1233 6160 0141 2
30 10103538 2222 1233 6160 0142 2

30 10103538 2222 1233 6160 0142 1
30 10103538 2222 1233 6160 0143 1
30 10103538 2222 1233 6160 0144 1
30 10103538 2222 1233 6160 0145 1
30 10103538 2222 1233 6160 0146 1