fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #define ll long long
  6. #define inf 0x3f3f3f3f
  7. #define minc(a,b) (((a)<(b)) ? (a) : (b))
  8. #define maxc(a,b) (((a)>(b)) ? (a) : (b))
  9. int read(){
  10. int ret=0,ttt=1;
  11. char ch=getchar();
  12. while(ch<'0' || ch>'9'){
  13. if(ch=='-'){
  14. ttt=-1;
  15. }ch=getchar();
  16. }while(ch>='0' && ch<='9'){
  17. ret=(ret<<1)+(ret<<3)+(ch^48);
  18. ch=getchar();
  19. }return ret*ttt;
  20. }
  21. struct info{
  22. char name[35],no[35],bp[35],age[5],sex[35];
  23. };
  24. struct info stu[130];
  25. //tran 负责把读入的整行字符串断成小部分赋值给目标对象。参数s为读入的整行字符串,tar为目标对象,i为计数器,l为整行长度。
  26. void tran(char *s, char *tar, int *i, int l){
  27. int cnt=0;
  28. //printf("%s %d\n",s,l);
  29. for(; (*i)<l; (*i)++){
  30. //printf("%d %c",*i,s[*i]);
  31. if(s[*i]==',') break;
  32. tar[cnt]=s[*i];
  33. cnt++;
  34. }
  35. //printf("\n");
  36. tar[cnt]='\0';
  37. return;
  38. }
  39. void input(int x){
  40. char s[200];
  41. gets(s);
  42. int l=strlen(s),ind=0;
  43. tran(s,stu[x].name,&ind,l);
  44. ind+=2;
  45. tran(s,stu[x].no,&ind,l);
  46. ind+=2;
  47. tran(s,stu[x].bp,&ind,l);
  48. ind+=2;
  49. tran(s,stu[x].age,&ind,l);
  50. ind+=2;
  51. tran(s,stu[x].sex,&ind,l);
  52. return;
  53. }
  54. void output(int x){
  55. printf("%s, %s, %s, %s, %s\n",stu[x].name,stu[x].no,stu[x].bp,stu[x].age,stu[x].sex);
  56. return;
  57. }
  58. //chk 检验a[y](定义与主函数中一致,查询请求的第y个信息)与stu[x]中某个信息完全一致,是则返回1.
  59. int chk(int y, int x, char (*a)[200]){
  60. int f=0;
  61. if(!strcmp(a[y],stu[x].name)) f=1;
  62. if(!strcmp(a[y],stu[x].no)) f=1;
  63. if(!strcmp(a[y],stu[x].bp)) f=1;
  64. if(!strcmp(a[y],stu[x].age)) f=1;
  65. if(!strcmp(a[y],stu[x].sex)) f=1;
  66. return f;
  67. }
  68. int main(){
  69. //freopen("Structure.in","r",stdin);
  70. //freopen("Structure.out","w",stdout);
  71. int n=read();
  72. for(int i=1; i<=n; i++){
  73. input(i);
  74. output(i);
  75. }
  76. char s[200],a[6][200];
  77. int l;
  78. while(1){
  79. gets(s);
  80. l=strlen(s);
  81. if(l>=4){
  82. if(s[0]=='q' && s[1]=='u' && s[2]=='i' && s[3]=='t') break;
  83. }
  84. int ind=0,cnt=0;
  85. while(ind<l){
  86. cnt++;
  87. tran(s,a[cnt],&ind,l);
  88. //printf("%s ",a[cnt]);
  89. ind++;
  90. }
  91. //printf("\n");
  92. int ans[130],num=0;
  93. for(int i=1; i<=n; i++){
  94. int f=1;
  95. for(int j=1; j<=cnt; j++){
  96. f=f && chk(j,i,a);
  97. }
  98. if(f){
  99. //f==1 代表请求中的所有信息都能在stu[i]中找到对应,i符合。
  100. num++;
  101. ans[num]=i;
  102. }
  103. }
  104. if(num!=1){
  105. printf("error\n");
  106. }else{
  107. output(ans[1]);
  108. }
  109. }
  110. return 0;
  111. }
Success #stdin #stdout 0s 5276KB
stdin
3
Yang Yang, 201701199, Beijing, 18, male
Meng Meng, 201701222, Sichuan, 19, male
Tian Tian, 201701666, Shanghai, 19, female
Yang Yang
201701666
male,18
male
female
19,male
female,19
male,19
quit
stdout
Yang Yang, 201701199, Beijing, 18, male
Meng Meng, 201701222, Sichuan, 19, male
Tian Tian, 201701666, Shanghai, 19, female
Yang Yang, 201701199, Beijing, 18, male
Tian Tian, 201701666, Shanghai, 19, female
Yang Yang, 201701199, Beijing, 18, male
error
Tian Tian, 201701666, Shanghai, 19, female
Meng Meng, 201701222, Sichuan, 19, male
Tian Tian, 201701666, Shanghai, 19, female
Meng Meng, 201701222, Sichuan, 19, male