现在的位置: 首页 > 综合 > 正文

浙大计算机研究生复试上机考试-2009年

2013年06月29日 ⁄ 综合 ⁄ 共 867字 ⁄ 字号 评论关闭

http://acm.hdu.edu.cn/showproblem.php?pid=3782

XXX定律

  1. #include "iostream"  
  2. using namespace std;  
  3. int main()  
  4. {  
  5.     int n;  
  6.     while (cin>>n&&n!=0)  
  7.     {  
  8.         int cnt=0;  
  9.         while(n!=1)  
  10.         {  
  11.             n=n%2?(n*3+1)>>1:n>>1;  
  12.             cnt++;  
  13.         }  
  14.         printf("%d\n",cnt);  
  15.     }  
  16. }  

ZOJ

  1. #include "iostream"  
  2. #include "string"  
  3. using namespace std;  
  4.   
  5. int main()  
  6. {  
  7.     string str;  
  8.     while(cin>>str&&str!="E")  
  9.     {  
  10.         int i;  
  11.         int count[26];  
  12.         memset(count,0,sizeof(int)*26);  
  13.         for (i=0;i<str.length();i++)  
  14.             count[str[i]-'A']++;  
  15.         int z='Z'-'A',o='O'-'A',j='J'-'A';  
  16.         while (count[z]>0||count[o]>0||count[j]>0)  
  17.         {  
  18.             if(count[z]-->0)  
  19.                 printf("Z");  
  20.             if(count[o]-->0)  
  21.                 printf("O");  

抱歉!评论已关闭.