zoukankan      html  css  js  c++  java
  • ZOJ Problem Set

    这道题目最让人头疼的就是该题的input怎么结束,因为它要求输入一个空行的时候则一串字符串输入结束,这就不得不让人绕个弯来解决这个问题。

    (注:本人习惯于使用C中的字符串操作,但是用到map要求使用string所以小绕弯)

    #include <map>
    #include <iostream>
    #include <string>
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    using namespace std;
    
    int main()
    {
    	map<string,string> dic;
    	map<string,string>::iterator iter;
    	char teng[15],tfm[15];
    	char tmp[25];
    	int n=0;
    
    	while(gets(tmp))
    	{
    		if(!strcmp(tmp,"")) break;
    		while(tmp[n]!='')
    		{
    			if(tmp[n]==' ')
    				break;
    			n++;
    		}
    
    		int i,j;
    		for(j=0;j<n;j++)
    			teng[j]=tmp[j];
    		teng[j]='';
    		for(j=n+1,i=0;j<strlen(tmp);i++,j++)
    			tfm[i]=tmp[j];
    		tfm[i]='';
    		string fm(tfm),eng(teng);
    		dic[fm]=eng;
    	}
    
    	char words[15];
    	while(gets(words))
    	{
    		if(!strcmp(words,"")) break;
    		iter=dic.find(words);
    		if(iter!=dic.end())
    			cout<<dic[words]<<endl;
    		else
    			printf("eh
    ");
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    java中 == 与equals 的区别
    java中的多线程 // 基础
    MySQL-锁机制
    将博客搬至CSDN
    MySQL-事务
    MySQL-存储过程
    MySQL-触发器
    MySQL-视图
    Redis设置Auth认证保护
    PHP目前常见的五大运行模式
  • 原文地址:https://www.cnblogs.com/xlturing/p/3300541.html
Copyright © 2011-2022 走看看