ZJU-3860-Find the Spy:get好多小经验
来源:互联网 发布:广告宣传语音制作软件 编辑:程序博客网 时间:2024/04/30 08:52
AC代码:我承认这方法太笨了
#include<iostream>#include<cmath>#include<string>#include<fstream>using namespace std;#define Max 100int main(){ ifstream cin("test.txt"); int T; int N; int Stu[Max+1]; cin>>T; int ans; while(T--){ cin>>N; cin>>Stu[0]; for( int i=1; i<N; i++ ){ cin>>Stu[i]; if( Stu[i] != Stu[i-1] ){ if( i==N-1 ) ans = Stu[i]; else{ cin>>Stu[i+1]; if( Stu[i]!=Stu[i+1] ) ans = Stu[i]; else ans = Stu[i-1]; i++; } } } cout<<ans<<endl; } return 0;}
需要考虑的要多,并且第一次交错了···
第一次交错是因为犯了老毛病-边读边计算,输出后直接跳出,结果 后续数据没有读进,WA···
以下是简答思路简单做法,毕竟 ACM 时间是很宝贵的···
对于此类签到题,要秒秒钟解决···
#include<iostream>#include<cmath>#include<string>#include<algorithm>#include<fstream>using namespace std;#define Max 100int main(){ ifstream cin("test.txt"); int T; int N; int Stu[Max+1]; cin>>T; int ans; while(T--){ cin>>N; for( int i=0; i<N; i++ ) cin>>Stu[i]; sort( Stu , Stu+N ); if( Stu[0]!=Stu[2] ) cout<<Stu[0]<<endl; else cout<<Stu[N-1]<<endl; } return 0;}
0 0
- ZJU-3860-Find the Spy:get好多小经验
- zoj 3860 Find the Spy
- ZOJ 3860: - Find the Spy
- ZOJ3860:Find the Spy
- ZOJ3860-Find the Spy
- Find the Spy
- Find the Spy
- zju 2839 Find the Sequences
- ZOJ Problem Set - 3860Find the Spy (STL-> map 建立简单查询表 )
- zju 1721 The Doors
- 数据流小问题--find the missing elements
- 【枚举+小技巧】【TOJ4115】【Find the number】
- A Spy in the Metro
- Uva1025A Spy in the Metro
- A Spy in the Metro
- ZJU 1610 Count the Colors
- ZJU P1610 count the colors
- spy++
- sql连接查询避免全表扫描
- mysql分表
- mybatis知识总结(四)初始化加载机制
- ARM寻址方式
- 图像的仿射变换与AffineTransform类
- ZJU-3860-Find the Spy:get好多小经验
- HDOJ Lowest Common Multiple Plus 2028
- 自定义cell高度实现简单通讯录
- Longest Substring Without Repeating Characters
- ARM汇编程序框架
- Android ViewGroup事件分发机制
- Eclipse常用设置
- C++ 静态数据成员 成员函数 静态变量 全局变量(2)
- android-APP长期运行于后台,重启后如何避免异常