zoukankan      html  css  js  c++  java
  • 蓝桥杯---简单试题集锦

    1、地址转换

        Excel是最常用的办公软件。每个单元格都有唯一的地址表示。比如:第12行第4列表示为:“D12”,第5行第255列表示为“IU5”。
        
        事实上,Excel提供了两种地址表示方法,还有一种表示法叫做RC格式地址。 第12行第4列表示为:“R12C4”,第5行第255列表示为“R5C255”。

        你的任务是:编写程序,实现从RC地址格式到常规地址格式的转换。

    【输入、输出格式要求】

        用户先输入一个整数n(n<100),表示接下来有n行输入数据。

        接着输入的n行数据是RC格式的Excel单元格地址表示法。

        程序则输出n行数据,每行是转换后的常规地址表示法。

        例如:用户输入:
    2
    R12C4
    R5C255

        则程序应该输出:
    D12
    IU5

    【注意】

        请仔细调试!您的程序只有能运行出正确结果的时候才有机会得分!
        
        在评卷时使用的输入数据与试卷中给出的实例数据可能是不同的。




    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    int main ( )
    {
        int n;
        cin>>n;
        while(n--)
        {
            string str;
            char ch [10]= {'0'},count=0;
            cin>>str;
            int len=str.length();
            int i=1,row=0,list=0;
            while(str[i]<='9'&&str[i]>='0' )
            {
                row=row*10+str[i]-'0';
                i++;
            }
            i++;
            while(i<len)
            {
                list=list*10+str[i]-'0';
                i++;
            }
           // cout<<row<<' '<<list<<endl;
    
            while(list>=26)
            {
                ch[count]=(char)('A'+list/26-1);
                count ++;
                list%=26;
            }
            ch[count++]=(char)('A'+list-1);
            for(int i=0; i<count; i++)
                cout<<ch[i];
            printf("%d
    ",row);
        }
        return 0;
    }


    猜算式


    看下面的算式:
    □□ x □□ = □□ x □□□
    它表示:两个两位数相乘等于一个两位数乘以一个三位数。

    如果没有限定条件,这样的例子很多。

    但目前的限定是:这9个方块,表示1~9的9个数字,不包含0。
    该算式中1至9的每个数字出现且只出现一次!

    比如:
    46 x 79 = 23 x 158
    54 x 69 = 27 x 138
    54 x 93 = 27 x 186
    .....

    请编程,输出所有可能的情况!

    注意:
    左边的两个乘数交换算同一方案,不要重复输出!
    不同方案的输出顺序不重要

    就是一个简单的全排,然后用到的一个重要算法就是暴力破解,重要思想。。。偷笑偷笑偷笑

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    int main (){
    int a[]={1,2,3,4,5,6,7,8,9},mark=0;
    int temp[20][4]={0},coun=0;
    while(next_permutation(a,a+9)){
    	for(int i=0;i<coun;i++){
    		if(a[0]==temp[i][0]&&a[1]==temp[i][1]&&a[2]==temp[i][2]&&a[3]==temp[i][3]){
    		mark=1;
    		break;
    		}	
    	}
    	if(mark) {  mark = 0;continue;}
    	if((a[0]*10+a[1])*(a[2]*10+a[3])==(a[4]*10+a[5])*(a[6]*100+a[7]*10+a[8])){
    	   printf("%d%d x %d%d = %d%d x %d%d%d
    ",a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]);
    	   temp[coun][0] = a[2],temp[coun][1] = a[3],temp[coun][2] = a[0],temp[coun++][3] = a[1];
    	}
    }
    return 0;
    }
    
    

    不过后来想想好像会超时的,应该还是会有时间限制的吧,所以又写了个新的算法,这样的话只要确定了前面的六位最后面的也就确定了,感觉应该比上面的一个快多了吧,恩恩,还不错...

    #include <stdio.h>
    #include <memory.h>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    void judge(int a,int b,int c,int d){
    	int temp[10]={0};
    	temp[a/10]++,temp[a%10]++;
    	temp[b/10]++,temp[b%10]++;
    	temp[c/10]++,temp[c%10]++;
    	temp[d/100]++,temp[d%100/10]++,temp[d%10]++;
    
     	for(int i=1;i<=9;i++)
    	 	if(temp[i]==0||temp[i]==2)
    	 	return ;
    	printf ("%d x %d = %d x %d
    ",a,b,c,d);
    }
    
    int main (){
    	for(int i=12;i<=98;i++){//第一个数
    		if(i%11==0||i%10==0) continue ;  
    		
    		for(int j=i;j<=98;j++){//第二个数
    			if(j%11==0||j%10==0) continue ;
    			
    			for(int x=12;x<=98;x++){//第三个数
    				if(x%11==0||x%10==0) continue;
    				
    				if(i*j%x!=0)  continue;    //如果第四个数不存在,跳一次
    				if( !(i*j/x<=987&&i*j/x>=100) ) continue;   //如果第四个数的范围不是三位数 ,跳过<pre name="code" class="cpp">
    				judge(i,j,x,i*j/x);
    			}
    		}
    	}
    return 0;
    }
    

    
    串的处理在实际的开发工作中,对字符串的处理是最常见的编程任务。本题目即是要求程序对用户输入的串进行处理。具体规则如下:1.    把每个单词的首字母变为大写。2.    把数字与字母之间用下划线字符(_)分开,使得更清晰3.    把单词中间有多个空格的调整为1个空格。例如:用户输入:you and     me what  cpp2005program则程序输出:You And
     Me What Cpp_2005_program用户输入:this is     a      99cat则程序输出:This Is A 99_cat我们假设:用户输入的串中只有小写字母,空格和数字,不含其它的字母或符号。每个单词间由1个或多个空格分隔。假设用户输入的串长度不超过200个字符。
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    int main (){
    string str="",str1="";
    char ch;
    while(~scanf("%c",&ch)&&ch!='
    ')
        str+=ch;
    int len = str.length();
    
    if(str[0]<='9'&&str[0]>='0')  str1+=str[0];
    else
    str1+=(char)str[0]-32;
    
    for(int i=1;i<len;i++){
    	if(str[i-1]==' '&&str[i]<='z'&&str[i]>='a')
    	   str1+=(char)str[i]-32;
    	else if(str[i-1]<='z'&&str[i-1]>='a'&&str[i]<='9'&&str[i]>='0')
    	    str1=str1+'_'+str[i];
    	else if(str[i]<='z'&&str[i]>='a'&&str[i-1]<='9'&&str[i-1]>='0')
    	    str1=str1+'_'+str[i];
    	else if(str[i-1]==' '&&str[i]==' ')
    	   continue;	
        else str1+=str[i];
    }
    cout<<str1;
    return 0;
    }
    
    

    取字符
    从标准输入读入一个由字母构成的串(不大于30个字符)。

    从该串中取出3个不重复的字符,求所有的取法。

    取出的字符,要求按字母升序排列成一个串。

    不同的取法输出顺序可以不考虑。

    例如:
    输入:
    abc
    则输出:
    abc

    输入:
    abcd
    则输出:
    abc
    abd
    acd
    bcd

    输入:
    abcaa
    则输出:
    abc
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    int main (){
    string str;
    char ch[35],coun = 0;
    cin>>str;
    int len = str.length();
    for(int i=0;i<len;i++){
    	int mark=0;
      for(int j=0;j<i;j++)
          if(str[i]==str[j])
            mark=1;
      if(mark==1) continue;
       ch[coun++]=str[i];
    }
    //
    sort(ch,ch+coun);
    for(int i=0;i<coun-2;i++)
       for(int j=i+1;j<coun-1;j++)
         for(int z=j+1;z<coun;z++)
           cout<<ch[i]<<ch[j]<<ch[z]<<endl;
    return 0;
    }
    
    


  • 相关阅读:
    crontab自动备份MySQL数据库并删除5天前备份
    使用ShowDoc在线管理API接口文档
    概率计算(抽奖活动、命中率)
    保护隐私?找回已记住的秘密?你的余额宝、淘宝还安全吗?
    自制公众平台Web Api(微信)
    我为什么期待M#?
    在.net中为什么第一次执行会慢?
    记”Uri.IsWellFormedUriString”中的BUG
    公司ERP系统重构那些事
    Koala Framework是什么?我为什么要写这个框架?
  • 原文地址:https://www.cnblogs.com/zswbky/p/5431992.html
Copyright © 2011-2022 走看看