zoukankan      html  css  js  c++  java
  • uva 128(简单题)

    题意:求一个字符串转化为2进制右移十六位加上一个数整除34943为零。

    思路:转化为大数求余数。

    代码如下:

     1 /**************************************************
     2  * Author     : xiaohao Z
     3  * Blog     : http://www.cnblogs.com/shu-xiaohao/
     4  * Last modified : 2014-03-25 08:21
     5  * Filename     : uva_128.cpp
     6  * Description     : 
     7  * ************************************************/
     8 
     9 #include <iostream>
    10 #include <cstdio>
    11 #include <cstring>
    12 #include <cstdlib>
    13 #include <cmath>
    14 #include <algorithm>
    15 #include <queue>
    16 #include <stack>
    17 #include <vector>
    18 #include <set>
    19 #include <map>
    20 #define MP(a, b) make_pair(a, b)
    21 #define PB(a) push_back(a)
    22 
    23 using namespace std;
    24 typedef long long ll;
    25 typedef pair<int, int> pii;
    26 typedef pair<unsigned int,unsigned int> puu;
    27 typedef pair<int, double> pid;
    28 typedef pair<ll, int> pli;
    29 typedef pair<int, ll> pil;
    30 
    31 const int INF = 0x3f3f3f3f;
    32 const double eps = 1E-6;
    33 const int LEN = 1010;
    34 char str[LEN], ch[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}, ans[LEN];
    35 
    36 void out(ll num){
    37     memset(ans, '0', sizeof ans);
    38     for(int i=3; num; i--){
    39         ans[i] = ch[num%16];
    40         num /= 16;
    41     }
    42 }
    43 
    44 int main()
    45 {
    46 //    freopen("in.txt", "r", stdin);
    47 
    48     while(gets(str)){
    49         if(str[0] == '#') break;
    50         int len = strlen(str);
    51            ll cs = 0;
    52         for(int i=0; i<len; i++){
    53             cs <<= 8;
    54             cs += str[i];
    55             cs %= 34943;
    56         }
    57         cs <<= 16;
    58         cs %= 34943;
    59         cs = 34943 - cs;
    60         cs %= 34943;
    61         out(cs);
    62         for(int i=0; i<=1; i++) cout << ans[i];
    63         cout << ' ';
    64         for(int i=2; i<=3; i++) cout << ans[i];
    65         cout << endl;
    66     }
    67     return 0;
    68 }
    View Code
  • 相关阅读:
    Android pm命令用法
    SSH没有password安全日志
    使用reserve要再次避免不必要的分配
    找到最大的迭代次数串
    个人存储不同类型的对象有一些想法的碰撞检测
    [Android 4.4.3] 泛泰A870 Mokee4.4.3 20140610 RC2.0 通过刷第三版 by syhost
    zoj 3823 Excavator Contest(结构体)
    【Linux】CentOS系统
    Swift学习——Swift解释特定的基础(七)
    Android JNI开发提高篇
  • 原文地址:https://www.cnblogs.com/shu-xiaohao/p/3624611.html
Copyright © 2011-2022 走看看