fork(1) download
  1. #include <bits/stdc++.h>
  2. #define Buff ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
  3. #define oo 1e9
  4. #define fi first
  5. #define se second
  6. #define ii pair<int,int>
  7. #define ll long long
  8. #define eps 0.00001
  9. #define Mask(i) (1LL<<(i))
  10. #define getbit(x,i) ((x>>(k-1))&1)
  11. #define cbit(x) __builtin_popcountll(x)
  12. #define onbit(x,k) ((x)|1LL<<(k-1))
  13. #define offbit(x,k) ((x)&~(1LL<<(k-1)))
  14. #define mod 1e9 + 7
  15. #define FU(i,a,b) for (int i=(a);i<=(b);i++)
  16. #define FD(i,a,b) for (int i=(a);i>=(b);i--)
  17. #define input freopen("1.inp","r",stdin)
  18. #define output freopen("1.out","w",stdout)
  19. #define pb push_back
  20. #define sz(x) (int)x.size()
  21. #define ALL(x) x.begin(),x.end()
  22. #define dad(i) (i+i&(-i))
  23. #define child(i) (i-i&(-i))
  24. #define endl '\n'
  25. using namespace std;
  26. const int maxn =1e5+1;
  27. string trace;
  28. int x,y;
  29.  
  30. void inp(){
  31. cin>>trace;
  32. }
  33. void cal_step(char move,int nsteps){
  34. // y asis
  35. if (move=='U'||move=='D'){
  36. y+=(move=='U'?nsteps:-nsteps);
  37. }
  38. // x asis
  39. if (move=='L'||move=='R'){
  40. x+=(move=='R'?nsteps:-nsteps);
  41. }
  42. }
  43. void isPrime(int a){
  44. if (a<=1) return;
  45. if (a%2==0&&a!=2) return;
  46. for (int i=3;i*i<=a;i+=2){
  47. if (a%i==0) return;
  48. }
  49. cout<<"Number "<<a<<" is prime number";
  50. }
  51. void isSquared(int a){
  52. int tmp=sqrt(a);
  53. if (tmp*tmp==a) cout<<"Number "<<a<<" is square number";
  54. }
  55. void run(){
  56. for (int i=0;i<=sz(trace)-1;i+=2) cal_step(trace[i],(int)trace[i+1]-'0');
  57. double d=sqrt(x*x+y*y);// distance
  58. int res=round(d);\
  59. cout<<"The distance the vehicle has moved from the origin to the current point is: "<<res<<endl;
  60. isPrime(res);
  61. isSquared(res);
  62. }
  63. int main(){
  64. Buff;
  65. // input;
  66. // output;
  67. inp();
  68. run();
  69. return 0;
  70. }
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
The distance the vehicle has moved from the origin to the current point is: 0
Number 0 is square number