juinda

Untitled

Oct 25th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. // 20161018 重複數字.cpp : 定義主控台應用程式的進入點。
  2. //
  3.  
  4. #include "stdio.h"
  5. #include<stdbool.h>
  6.  
  7. int main()
  8. {
  9. char num[100];
  10. while (gets(num) != NULL)
  11. {
  12. bool repeat[10] = { 0 };
  13. bool sp = 0;
  14. for (int i = 0; num[i] != '\0'; i++)
  15. {
  16. for (int j = 0; num[j] != '\0'; j++)
  17. {
  18. if (i == j)j++;
  19. if (num[i] == num[j])
  20. {
  21. repeat[num[i] - '0']=1;
  22. }
  23. }
  24. }
  25. for (int i = 0; i < 10; i++)
  26. {
  27. if (repeat[i] == 1)
  28. {
  29. if (sp)printf(" ");
  30. printf("%d", i);
  31. sp = 1;
  32. }
  33. }
  34. if (sp)puts("");
  35. if (!sp) puts("No repeated digit.");
  36. }
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment