fork download
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. char str[1000002];
  5. char x[30],y[30];
  6.  
  7. int main()
  8. {
  9. int t;
  10. scanf("%d",&t);
  11. while(t--)
  12. {
  13. int n,op,k;
  14. char c;
  15. scanf("%d",&n);
  16. op=n;
  17. int i=0;
  18. while(n--)
  19. {
  20. c=getchar();
  21. x[i]=getchar();
  22. // printf("x[%d]=%d\n",i,x[i]);
  23. c=getchar();
  24. y[i]=getchar();
  25. i++;
  26. }
  27. // printf("n= %d \n%d %d \n%d %d\n",n,x[0],y[0],x[1],y[1]);
  28. scanf("%s",str);
  29. int j,loc=-1,len=strlen(str);
  30.  
  31. for(i=0;i<len;i++)
  32. {
  33. for(j=0;j<op;j++)
  34. {
  35. if(str[i]==x[j])
  36. {
  37. str[i]=y[j];
  38. break;
  39. }
  40. }
  41. }
  42. // printf("string now = %s\n",str);
  43.  
  44. for(j=0;j<len && str[j]=='0';j++)
  45. {
  46. }
  47.  
  48. for(k=len-1;k>=0 && str[k]=='0';k--)
  49. {
  50. }
  51.  
  52. for(i=0;i<len;i++)
  53. {
  54. if(str[i]=='.')
  55. {
  56. loc=i;
  57. break;
  58. }
  59. }
  60. // printf("j=%d and k=%d\n",j,k);
  61.  
  62. if(loc==-1)
  63. {
  64. if(k<j)
  65. printf("0\n");
  66.  
  67. else
  68. {
  69. for(i=j;i<len;i++)
  70. printf("%c",str[i]);
  71. printf("\n");
  72. }
  73. }
  74. else
  75. {
  76. if(k==j)
  77. printf("0\n");
  78. else if(loc==j)
  79. {
  80. for(i=loc;i<=k;i++)
  81. printf("%c",str[i]);
  82. printf("\n");
  83. }
  84. else if(loc==k)
  85. {
  86. for(i=j;i<=loc-1;i++)
  87. printf("%c",str[i]);
  88. printf("\n");
  89. }
  90. else
  91. {
  92. for(i=j;i<=k;i++)
  93. printf("%c",str[i]);
  94. printf("\n");
  95. }
  96. }
  97. /*
  98. if(k<j)
  99. printf("0\n");
  100.  
  101. else
  102. {
  103. for(i=j;i<=k;i++)
  104. printf("%c",str[i]);
  105. printf("\n");
  106. }
  107. */
  108. }
  109. return 0;
  110. }
Success #stdin #stdout 0s 3228KB
stdin
2
0
000
0
0.1
stdout
0
.1