zoukankan      html  css  js  c++  java
  • hdu 1228 A+B 字符串处理 超级大水题

    中文意思不解释。

    很水,我本来想用switch处理字符串,然后编译不通过。。。原来switch只能处理整数型的啊,我都忘了。

    然后就有了很挫的一大串if代码了。。。

    代码:

    #include <iostream>
    #include <string>
    using namespace std;
    
    int digit(string str) {
    	if (str == "zero")
    		return 0;
    	if (str == "one")
    		return 1;
    	if (str == "two")
    		return 2;
    	if (str == "three")
    		return 3;
    	if (str == "four")
    		return 4;
    	if (str == "five")
    		return 5;
    	if (str == "six")
    		return 6;
    	if (str == "seven")
    		return 7;
    	if (str == "eight")
    		return 8;
    	if (str == "nine")
    		return 9;
    	return -1;
    }
    
    int getval() {
    	string tmp;
    	int s = 0;
    	while (cin >> tmp && tmp != "+" && tmp != "=") {
    		s = s * 10 + digit(tmp);
    //		cout << tmp << endl;
    	}
    	return s;
    }
    
    int main() {
    	int p1, p2;
    	while (1) {
    		p1 = getval();
    		p2 = getval();
    //		cout << p1 << " + " << p2 << " = "<< endl;
    		if (p1 == 0 && p2 == 0)
    			break;
    		cout << p1 + p2 << endl;
    	}//while
    	return 0; 
    }


  • 相关阅读:
    模拟hadoop-rpc通信
    IOUtils方式上传下载文件
    HDFS基本操作的API
    HDFS基本命令行操作及上传文件的简单API
    gcj_2016_Round1_B
    hiho_1070_RMQ
    hiho_1068_RMQ_st算法
    hiho_1067_最近公共祖先2
    hiho_1062_最近公共祖先
    hiho_1066_并查集
  • 原文地址:https://www.cnblogs.com/java20130723/p/3212231.html
Copyright © 2011-2022 走看看