• 蓝桥杯-错误票据 (水)


      历届试题 错误票据  
    时间限制:1.0s   内存限制:256.0MB
          
    问题描述

    某涉密单位下发了某种票据,并要在年终全部收回。

    每张票据有唯一的ID号。全年所有票据的ID号是连续的,但ID的开始数码是随机选定的。

    因为工作人员疏忽,在录入ID号的时候发生了一处错误,造成了某个ID断号,另外一个ID重号。

    你的任务是通过编程,找出断号的ID和重号的ID。

    假设断号不可能发生在最大和最小号。

    输入格式

    要求程序首先输入一个整数N(N<100)表示后面数据行数。

    接着读入N行数据。

    每行数据长度不等,是用空格分开的若干个(不大于100个)正整数(不大于100000),请注意行内和行末可能有多余的空格,你的程序需要能处理这些空格。

    每个整数代表一个ID号。

    输出格式

    要求程序输出1行,含两个整数m n,用空格分隔。

    其中,m表示断号ID,n表示重号ID

    样例输入1
    2
    5 6 8 11 9 
    10 12 9
    样例输出1
    7 9
    样例输入2
    6
    164 178 108 109 180 155 141 159 104 182 179 118 137 184 115 124 125 129 168 196
    172 189 127 107 112 192 103 131 133 169 158 
    128 102 110 148 139 157 140 195 197
    185 152 135 106 123 173 122 136 174 191 145 116 151 143 175 120 161 134 162 190
    149 138 142 146 199 126 165 156 153 193 144 166 170 121 171 132 101 194 187 188
    113 130 176 154 177 120 117 150 114 183 186 181 100 163 160 167 147 198 111 119
    样例输出2
    105 120

    题解:水题,排序,找重;

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<set>
    using namespace std;
    #define mem(x,y) memset(x,y,sizeof(x))
    #define SI(x) scanf("%d",&x)
    #define PI(x) printf("%d",x)
    #define P_ printf(" ")
    const int INF=0x3f3f3f3f;
    typedef long long LL;
    const int MAXN=100010;
    int m[MAXN];
    char s[MAXN];
    int main(){
    	int N,len;
    	while(~SI(N)){
    		int t=0;
    		mem(m,0);
    		getchar();
    		for(int i=0;i<N;i++){
    			gets(s);
    			len=strlen(s);
    			for(int j=0;j<len;j++){
    				int flot=0;
    				while(s[j]&&isdigit(s[j])){
    					m[t]=m[t]*10+s[j++]-'0';
    					flot=1;
    				}
    				if(flot)t++;
    			}
    		}
    		sort(m,m+t);
    		int ans=m[0],ans2=m[0];
    		for(int i=1;i<t;i++){
    			if(m[i]-m[i-1]>=2){
    				ans=m[i]-1;
    			}
    			if(m[i]==m[i-1])ans2=m[i];
    		}
    		printf("%d %d
    ",ans,ans2);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    shell命令编程小例
    汇编输出0255ascii码(VGA下)
    linux程序时间控制小例
    Undefined exploded archive location 项目不能部署
    关于org.apache.jasper.JasperException: Unable to compile class for JSP问题的解决
    Some characters cannot be mapped using "GBK" character encoding 的解决办法
    如何处理Windows Forms程序中未处理的异常
    关于bos的edit页面的文件加载顺序
    关于unable to extend lob segment的问题解决方法
    从事ASP.NET开发两年多,谈谈对两三年工作经验的ASP.NET程序员的基本见解
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5099543.html
Copyright © 2020-2023  润新知