zoukankan      html  css  js  c++  java
  • 百炼OJ

    题目链接

    思路

    开个一千万的数组计数,最后遍历即可。

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    
    using namespace std;
    int num=0;
    int mymap[10000000] = {0};
    
    int change(char a[201])
    {
    	int j=0, result=0;
    	for(int i=0;i<strlen(a);i++)
    	{
    		if(a[i] == '-') continue;
    		if(a[i] <= '9' && a[i] >= '0')
    		{
    			result = result*10+a[i]-'0';
    			continue;
    		}
    		if( a[i] <= 'O' && a[i] >= 'A' )
    		{
    			result = result*10+ (int)((a[i]-'A')/3) + 2;
    			continue;
    		}
    		switch (a[i])
    		{
    			case 'P':
    			case 'R':
    			case 'S':
    				result = result*10+7;
    				break;
    			case 'T':
    			case 'U':
    			case 'V':
    				result = result*10+8;
    				break;
    			case 'W':
    			case 'X':
    			case 'Y':
    				result = result*10+9;
    				break;
    		}
    	}
    	return result;	
    } 
    int main()
    {
    	int n,times=0;
    	char temp[201];
    	scanf("%d",&n);
    	for(int i=0;i<n;i++)
    	{
    		scanf("%s",temp);
    		int flag = 0, t;
    		t = change(temp);
    		mymap[t] ++;
    	}
    	
    	int flag = 0;
    	for(int i=0;i<10000000;i++)
    	{
    		if(mymap[i] < 2) continue;
    		flag = 1;
    		char p[8] = {0};
    		sprintf(p,"%d",i);
    		if( strlen(p) <= 4 )
    		{
    			for(int j=0;j<3;j++)
    				printf("0");
    			printf("-");
    			for(int j=0;j<4-strlen(p);j++)
    				printf("0");
    			for(int j=0;j<strlen(p);j++)
    				printf("%c",p[j]);
    		}
    		else
    		{
    			for(int j=0;j<7-strlen(p);j++)
    				printf("0");
    			for(int j=0;j<strlen(p)-4;j++)
    				printf("%c",p[j]);
    			printf("-");
    			for(int j=strlen(p)-4;j<strlen(p);j++)
    				printf("%c",p[j]);
    		}
    		printf(" %d
    ",mymap[i]);
    	}
    	if( flag == 0 ) puts("No duplicates.");
    	return 0;	
    } 
    
  • 相关阅读:
    新浪微博学习的知识点
    新浪项目笔记
    2015年10月20日整理知识
    版本管理工具 (git 或者 svn)
    Coding 代码push/commit/pull/git clone
    fileurlwithpath urlwithstring 这俩有啥区别吗
    正则表达式
    地图
    各种杂项
    实时通讯
  • 原文地址:https://www.cnblogs.com/L1B0/p/10905378.html
Copyright © 2011-2022 走看看