zoukankan      html  css  js  c++  java
  • 题解 P1765 【手机_NOI导刊2010普及(10)】

    说实话,打表真的很累!
    所以小金羊又开始暴力出奇迹了!
    这个题解适合初学者使用。


    知识点:string里面的str.find()函数:
    可以查找字符串和字符,有就返回位置(开头是0),
    没有就返回string::npos(unsigned int npos=-1)。
    所以就可以开始微型打表微型暴力了:
    Code:

    #include <iostream>
    #include <cstdio>
    #include <string>
    using namespace std;
    string str[10]={"","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"," "};
    int main()
    {
    	int count=0,i;
    	char inp;
    	while (scanf("%c",&inp)!=EOF)
    	{//据说会吞回车
    		for(i=1;i<=9;i++)
    		{//从九个预设字符串里找吧
    			if (str[i].find(inp,0)!=string::npos)
    			{//如果在这个预设字符串内,
    				count=count+str[i].find(inp,0)+1;
                    break;
    			}//位置+1就是需要按的次数。
    		}
    	}
    	printf("%d",count);
    	return 0;
    }
    

    效果明显,秒杀if,case,打表...

  • 相关阅读:
    C++命名规则
    protobuf_1
    以太网帧格式
    LinQ
    asp.mvc 基本知识
    Lucene.Net 优化索引生成,即搜索显示优化
    HTML Meta中添加X-UA-Compatible和IE=Edge,chrome=1有什么作用
    DataSet
    伪Excel导出新版代码
    WebUI 常用
  • 原文地址:https://www.cnblogs.com/jelly123/p/10385936.html
Copyright © 2011-2022 走看看