zoukankan      html  css  js  c++  java
  • 《2017年内蒙古自治区第十二届大学生程序设计-超级密码》

    题目描述

    DD小朋友今年三年级,最近,声称设计了一套“超级密码”系统!
    说实话,这套所谓的“超级密码”一点也不难:
    对于一个给定的字符串,你只要提取其中的数字,然后连在一起构成一个整数,再乘以DD小朋友的幸运数字513,就是解密后的结果了~
    比如,字符串“ads2d4,122”,提取后的整数是24122,然后乘以513,就能得到解密后的结果:12374586。
    注:题目保证解密后的结果在32位整数范围。

    输入格式

    输入首先包括一个正整数N,表示有N组测试用例。
    每组数据占一行,包含一个长度不超过30的字符串。

    输出格式

    请根据题目要求输出解密后的结果,每组数据输出一行。

    输入样例 复制

    2
    ads2d4,122
    0023asdf2AA90
    

    输出样例 复制

    12374586
    11947770



    c++ AC代码:
    # include <iostream>
    # include <string>
    # include <math.h>
    using namespace std;
    
    int getNumber(string content){
        int array[40];
        bool flag = false;
        int flag_index = -1;
        int sum = 0;
        int count = 0;
        for(int i = 0;i<content.length();i++)
        {
            if(content[i]>=48&&content[i]<=57){
                array[count] = content[i]-48;
                count++;
            }
        }
    
    
        
        if(array[0]!=0){
            flag = true;
        }
    
        if(flag){
            int temp =count;
            for(int n = 0;n<count;n++){
                temp--;
                sum += array[n]*pow(10,temp);
            }
        }
        else{
            for(int m = 0;m<count;m++){
                if(m!=0){
                    flag_index= m;
                    break;
                }
            }
            int temp = count - flag_index;
            for(int index = flag_index;index<count;index++){
                temp--;
                sum += array[index]*pow(10,temp);
            }
        
        }
    
    
        return sum*513;
    }
    
    int main(){
    
        int n;
        cin>>n;
        for(int i =0;i<n;i++){
            string content;
            cin>>content;
            cout<<getNumber(content)<<endl;
            
        }
        return 0;
    }

    Java 代码实现  已AC

     1 import java.util.Scanner;
     2 
     3 public class Main {
     4     
     5     public static int getResult(String content){
     6         
     7         int result = 0;
     8         for(int i = 0;i<content.length();i++){
     9             if(content.charAt(i)>='0'&&content.charAt(i)<='9')
    10             {
    11                 result=result*10+content.charAt(i)-48;
    12             }
    13         }
    14         return result*513;
    15     }
    16 
    17     public static void main(String[] args) {
    18         Scanner cin = new Scanner(System.in);
    19         int n = cin.nextInt();
    20         for(int count = 0;count<n;count++){
    21             String content = cin.next();
    22             System.out.println(getResult(content));
    23         }
    24     }
    25 
    26 }
  • 相关阅读:
    Ubuntu Linux Matlab 安装 中文乱码 桌面启动器 Could not find the main class: java/splash.png. 终端terminal 直接运行 matlab
    Ubuntu Linux 官网 u盘安装 u盘系统 图文教程
    从google map google earth获得大图 方法总结
    论文查重网址
    [ZZ] Computer Science Conference Rankings
    Ubuntu linux 信使 iptux Window 飞鸽 ipmsg 飞秋 feiq 文件传输
    Ubuntu Linux Matlab mex
    Ubuntu Dell OptiPlex 990 Intel Gigabit CT Desktop Adapter网卡驱动安装
    C++的File类文件操作
    GIS软件比较
  • 原文地址:https://www.cnblogs.com/kangxinxin/p/10679462.html
Copyright © 2011-2022 走看看