ZOJ 2104 ZOJ 1110
2015-12-12 23:35
197 查看
不清楚为什么我的编译器上strcpy_s()可以运行通过,到了ZOJ上就不行了 就会出现编译错误
//ZOJ 2104 #include<stdio.h> #include<cstring> #include<algorithm> #include<fstream> #include<iostream> using namespace std; struct str { //该结构体中的两个变量分别记录:字符变量(在输入系统中出现的),每个字符出现的次数 char s[100]; int num; }; str a[100]; void Init(int n) { //将每个字符出现的次数都初始化为零 for (int i = 0; i < n; i++) { a[i].num = 0; } } bool cmp(str a, str b) { //重写比较函数(按照从大到小的顺序排列) return a.num>b.num; } int main() { ifstream cin("F://ac.txt"); int j, n; char b[100]; while (true) { cin >> n; if (n == 0) { break; } Init(n); //读入第一个字符 cin >> a[0].s; //记录当前出现了多少个不同的字符 int count = 0; for (int i = 1; i < n; i++) { //开始读入后面的字符 cin >> b; for (j = 0; j <= count; j++) { //在已存在的字符中查找是否有和新读入的字符相同的字符,如果存在则将 //该字符的num++ if (strcmp(b, a[j].s) == 0) { a[j].num++; break; } } if (j - 1 == count) { //该条件的意义是如果在已存在的字符中没有找到符合条件的字符 //则将该字符插入到一个新的位置上去 strcpy_s(a[++count].s, b); } } //对数组进行排列,并输出出现频率最高的 sort(a, a + count + 1, cmp); cout << a[0].s << endl; } return 0; } //ZOJ 1110 #include <stdio.h> int main(void) { int j, a, b, c, s, p, y; while (scanf("%d%d%d%d", &s, &p, &y, &j) != EOF) { for (a = 12 + j - 1; a >= s + p; a--) for (b = p; b <= 12 + j - a; b++) { c = 12 + j - b - a; if ( (a == b + s || a == b + s + 1) && (b == c + p || b == c + p + 1) && (a == y + c || a == y + c + 1) ) goto X; } X: printf("%d %d %d\n", a, b, c); } return 0; }
相关文章推荐
- 来,咱们自己写一个Android的IOC框架!
- Ovirt-engine-backup
- Nginx的负载均衡 - 加权轮询 (Weighted Round Robin) 上篇
- OpenPortalServer V3.3.10.2 2015-12-12发布
- 使用andbase开发框架实现绘制折线图
- 利用反射机制,获取类的字段、方法、并实现简单调用
- Nginx的负载均衡 - 加权轮询 (Weighted Round Robin) 上篇
- 2-Twelfth Scrum Meeting20151212
- 烘焙圈总结
- c语言:算数转换举例
- 牛客网 debug-release http://www.nowcoder.com/profile/380772/test/2198844/36245?onlyWrong=0
- C 实现 字符串 去前后空白符的函数 strtrim
- 使用百度云推送实现推送功能详解
- LAMP 3.2 mysql登陆
- 王学岗异步机制 AsyncTask
- 简易版井字棋 (MouseListener需重写所有函数&&数组对象设置监听方法)
- LayoutInflater—— 你可能对它并不了解甚至错误使用
- 信息更新小红点显示——自定义控件BadgeView的使用介绍
- 点击后弧形展开的炫酷菜单--第三方开源-- CircularFloatingActionMenu(一)
- (转)Array.prototype.slice.call自解