Advertisement
Eather

Two code of Ashraf sir... compiler

Mar 11th, 2011
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.02 KB | None | 0 0
  1. //////////////////email checker//////////////////////
  2.  
  3.                            /*in the name of Allah */
  4.  
  5. # include <list>
  6. # include <deque>
  7. # include <bitset>
  8. # include <algorithm>
  9. # include <functional>
  10. # include <numeric>
  11. # include <utility>
  12. # include <sstream>
  13. # include <iostream>
  14. # include <iomanip>
  15. # include <cstdio>
  16. # include <cmath>
  17. # include <cstdlib>
  18. # include <ctime>
  19. # include <set>
  20. # include <map>
  21. # include <cmath>
  22. # include <queue>
  23. # include <limits>
  24. # include <stack>
  25. # include <vector>
  26. # include <cstring>
  27. # include <cstdio>
  28. using namespace std;
  29.  
  30. # define all(c) (c).begin(), (c).end()
  31.  
  32. template<class T> string toString(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();}
  33. int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
  34.  
  35.  
  36. int main()
  37. {
  38.  
  39. int ca=0;
  40. string s;
  41.  
  42. while(cin>>s){
  43.  
  44. string t="";
  45.  
  46. int bo=0;
  47. if(s[0]>='0' && s[0]<='9')bo=0;else bo=1;
  48.  
  49. for(int i=0;i<s.size();i++)t+=(char)tolower(s[i]);
  50.  
  51. reverse(all(t));
  52. int at=0;
  53. if(bo==1)if(t.substr(0,4)=="moc.")
  54. {
  55.   bo=1;
  56. }else bo=0;
  57.  
  58. int pos=-1;
  59.  
  60. if(bo==1)
  61. {
  62.   for(int i=4;i<t.size();++i)
  63.   {
  64.     if(t[i]=='@'){at=1;break;}
  65.     pos=i;
  66.     if((t[i]>='a' && t[i]<='z') || t[i]=='.')
  67.     bo=1;
  68.     else bo=0;
  69.     if(t[i]=='.' && (t[i+1]=='.' || t[i-1]=='.'||t[i+1]=='@'))bo=0;
  70.  
  71.     if(bo==0)break;}
  72.  
  73. }
  74.  
  75. if(bo==1)
  76. {
  77.   for(int i=pos+2;i<t.size();i++)
  78.   {if((t[i]>='a'&& t[i]<='z')||(t[i]>='0' && t[i]<='9'))bo=1;
  79.   else bo=0;
  80.  
  81.   if(bo==0)break;}
  82. }
  83.  
  84. if(bo==1 && pos>=4 && at==1)cout<<"Valid Email"<<endl;else cout<<"Invalid Email"<<endl;
  85. }
  86. return 0;
  87.  
  88. }
  89.  
  90.  
  91.  
  92. /////////////////////////////////////////////////////////////////
  93.  
  94. //////////////////Expression Identifier/////////////////////////
  95.  
  96.                            /*in the name of Allah */
  97.  
  98. # include <list>
  99. # include <deque>
  100. # include <bitset>
  101. # include <algorithm>
  102. # include <functional>
  103. # include <numeric>
  104. # include <utility>
  105. # include <sstream>
  106. # include <iostream>
  107. # include <iomanip>
  108. # include <cstdio>
  109. # include <cmath>
  110. # include <cstdlib>
  111. # include <ctime>
  112. # include <set>
  113. # include <map>
  114. # include <cmath>
  115. # include <queue>
  116. # include <limits>
  117. # include <stack>
  118. # include <vector>
  119. # include <cstring>
  120. # include <cstdio>
  121. using namespace std;
  122.  
  123. # define all(c) (c).begin(), (c).end()
  124.  
  125. template<class T> string toString(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();}
  126. int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
  127.  
  128. bool chk(string s,string sit)
  129. {
  130.   if(sit=="flt")
  131.   {
  132.     int f=0;
  133.     for(int i=0;i<s.size();i++)
  134.     {
  135.       if(s[i]=='.')f++;
  136.       if(s[i]=='.')if(s[i+1]=='.' || s[i-1]=='.')return false;
  137.  
  138.       if((char)tolower(s[i])>='a' && (char)tolower(s[i])<='z')return false;
  139.     }
  140.     if(f>1)return false;
  141.   }
  142.  
  143.   if(sit=="sci")
  144.   {
  145.     int f=0,ss=0;
  146.     for(int i=0;i<s.size();i++)
  147.     {
  148.       if(s[i]=='.')f++;
  149.       if(s[i]=='E')ss++;
  150.       if(s[i]=='.')if(s[i+1]=='E')return false;
  151.       if(s[i]=='.')if(s[i+1]=='.')return false;
  152.       if(s[i]=='E')if(s[i+1]=='.')return false;
  153.       if(s[i]=='E')if(s[i+1]=='E')return false;
  154.     }
  155.     if(f>1 || ss>1 || ss==0)return false;
  156.   }
  157.   return true;
  158. }
  159.  
  160. bool cmp(string s, string t)
  161. {
  162.   if(s.size()<t.size())return true;
  163.   else if(s<t)return true;
  164.  
  165.   return false;
  166. }
  167.  
  168. int main()
  169. {
  170.  
  171. int ca=0;
  172. string s;
  173. while(1){
  174.  
  175. vector<string>ni;
  176.  
  177. getline(cin,s);
  178.  
  179. stringstream t(s);
  180.  
  181. while(t>>s)
  182. {
  183.   ni.push_back(s);
  184. }
  185.  
  186.  
  187. int sci=0,in=0,flt=0,ide=0,inv=0,ope=0;
  188.  
  189. vector<string>integer,floating,identifier,operators,scientific,invalid;
  190. for(int i=0;i<ni.size();i++)
  191. {
  192.   sci=0,in=0,flt=0,ide=0,inv=0,ope=0;
  193.   if(ni[i][0]=='+'|| ni[i][0]=='-'||ni[i][0]=='*'||ni[i][0]=='/' || ni[i][0]=='=')ope=1;
  194.   else if(ni[i][0]>='0' && ni[i][0]<='9')
  195.   {
  196.  
  197.   for(int j=1;j<ni[i].size();j++)
  198.   {
  199.     if(ni[i][j]>='a' && ni[i][j]<='z'){inv=1;goto a;}
  200.     else if((ni[i][j]=='.' && (ni[i][j-1]!='E' || ni[i][j+1]!='E')) && (ni[i][j]=='E' && ni[i][j-1]!='.') && ni[i][j]=='E'){if(chk(ni[i],"sci"))sci=1;else if(chk(ni[i],"sci"))flt=1; else inv=1;goto a;}
  201.     else if(ni[i][j]=='.' && ni[i][j]!='E'){if(chk(ni[i],"flt")){flt=1;}else if(chk(ni[i],"sci"))sci=1; else inv=1; goto a;}
  202.     else if(ni[i][j]!='.' && ni[i][j]=='E'){if(chk(ni[i],"sci"))sci=1;else inv=1;goto a;}
  203.   }
  204.   in=1;
  205.   }
  206.   else if( (ni[i][0]>='a' && ni[i][0]<='z') || (ni[i][0]>='A' && ni[i][0]<='Z') || ni[i][0]=='_') ide=1;
  207.   else inv=1;
  208.  
  209.   //cout<<ni[i]<<" "<<sci<<" "<<in<<" "<<inv<<" "<<ope<<" "<<ide<<" "<<flt<<endl;
  210.   a:
  211.     if(sci==1)scientific.push_back(ni[i]);
  212.     if(sci!=1 || inv!=1 || flt!=1) if(in==1)integer.push_back(ni[i]);
  213.     if(inv==1)invalid.push_back(ni[i]);
  214.     if(ope==1)operators.push_back(ni[i]);
  215.     if(ide==1)identifier.push_back(ni[i]);
  216.     if(sci!=1 && flt==1)floating.push_back(ni[i]);
  217. }
  218. if(ni.size()>=1){
  219. identifier.erase(unique(all(identifier)),identifier.end());
  220.  
  221. sort(all(identifier),cmp);
  222.  
  223. cout<<"Identifires are: ";
  224. for(int i=0;i<identifier.size();i++)cout<<identifier[i]<<" ";
  225. cout<<endl;
  226.  
  227. integer.erase(unique(all(integer)),integer.end());
  228.  
  229. sort(all(integer),cmp);
  230.  
  231. cout<<"Integers are: ";
  232. for(int i=0;i<integer.size();i++)cout<<integer[i]<<" ";
  233. cout<<endl;
  234.  
  235. floating.erase(unique(all(floating)),floating.end());
  236.  
  237. sort(all(floating),cmp);
  238.  
  239.  
  240. cout<<"floatings are: ";
  241. for(int i=0;i<floating.size();i++)cout<<floating[i]<<" ";
  242. cout<<endl;
  243.  
  244. scientific.erase(unique(all(scientific)),scientific.end());
  245.  
  246. sort(all(scientific),cmp);
  247.  
  248. cout<<"Scientific numbers are: ";
  249. for(int i=0;i<scientific.size();i++)cout<<scientific[i]<<" ";
  250. cout<<endl;
  251.  
  252. operators.erase(unique(all(operators)),operators.end());
  253.  
  254. sort(all(operators),cmp);
  255.  
  256. cout<<"Operators are: ";
  257. for(int i=0;i<operators.size();i++)cout<<operators[i]<<" ";
  258. cout<<endl;
  259.  
  260. invalid.erase(unique(all(invalid)),invalid.end());
  261.  
  262. sort(all(invalid),cmp);
  263.  
  264. cout<<"Invalids are: ";
  265. for(int i=0;i<invalid.size();i++)cout<<invalid[i]<<" ";
  266. cout<<endl;
  267. }
  268. else
  269. cout<<endl<<endl;
  270. }
  271. return 0;
  272.  
  273. }
  274. ////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement