scanf

Codeforces Round #572 (Div. 2)

不想你离开。 提交于 2020-03-05 23:15:02
A. Keanu Reeves 所有“字符串”均为0,1组成。定义好串:0和1字符数不相等 坏串:0和1字符数相等 给一个字符串 问:最小拆分分成几个字符串可以全部变成好串 解法:字符串有可能0,1的数量不相等,本来就是好串。直接输出1和原字符串。字符串0,1数量也可能相等,是坏串。我们只需单独把字符串第一个字符和剩余字符串分别输出。两个必定都是好串。此时拆分成了两个子字符串,故只有1和2两种情况。 #include <iostream> using namespace std; int n; char a[1010]; int temp; int main() { scanf("%d",&n); scanf("%s",a); for(int i=0;i<n;i++) { if(a[i]-'0'==1) temp++; if(a[i]-'0'==0) temp--; } if(temp!=0) { printf("1\n"); for(int i=0;i<n;i++) { printf("%d",a[i]-'0'); } } if(temp==0) { printf("2\n"); printf("%d ",a[0]-'0'); for(int i=1;i<n;i++) printf("%d",a[i]-'0'); } printf("\n"); } View Code B.

DEV C++调试,scanf无法输入,运行框无法输入

冷暖自知 提交于 2020-03-05 22:27:40
今天在使用DEVdebug的时候发现怎么都无法输入变量,可把我给搞郁闷了,经过查阅后,忽然发现自己的断点设置在了scanf()输入的语句上,哎 断点要设置在scanf语句之后,否则会被阻塞掉。呜呜呜呜呜~~这一错误犯得太冤了。 来源: CSDN 作者: 永不秃头. 链接: https://blog.csdn.net/weixin_44164333/article/details/104683644

CodeCraft-20 (div 2) 做题记录

女生的网名这么多〃 提交于 2020-03-05 18:50:42
A. 把所有都放到1号上就行了 1 #include<bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 int T,n,m; 5 int main() 6 { 7 scanf("%d",&T); 8 while(T--) 9 { 10 scanf("%d%d",&n,&m); 11 int s=0; 12 for(int x,i=1;i<=n;++i)scanf("%d",&x),s+=x; 13 printf("%d\n",min(m,s)); 14 } 15 } View Code B. 找规律,长度为k的翻转是从k开始的一个后缀拼上剩下的前缀 这个前缀可能是正着的可能是反着的,发现和n,k的奇偶性有关 1 #include<bits/stdc++.h> 2 #define maxn 5005 3 using namespace std; 4 int T,n; 5 char str[maxn]; 6 pair<string,int> s[maxn]; 7 int main() 8 { 9 scanf("%d",&T); 10 while(T--) 11 { 12 memset(str,0,sizeof(str)); 13 scanf("%d",&n); 14 scanf("%s",str+1); 15

深入理解GOT表和PLT表

孤街浪徒 提交于 2020-03-05 15:25:15
0x01 前言 操作系统通常使用动态链接的方法来提高程序运行的效率。 在动态链接的情况下,程序加载的时候并不会把链接库中所有函数都一起加载进来,而是程序执行的时候按需加载,如果有函数并没有被调用,那么它就不会在程序生命中被加载进来。 这样的设计就能提高程序运行的流畅度,也减少了内存空间。而且现代操作系统不允许修改代码段,只能修改数据段,那么GOT表与PLT表就应运而生。 0x02 初探GOT表和PLT表 我们先简单看一个例子 我们跟进一下scanf@plt 会发现,有三行代码 jmp 一个地址 push 一个值到栈里面 jmp 一个地址 看函数的名字就可以知道这是scanf函数的plt表,先不着急去了解plt是做什么用的,我们继续往下看 我们先看一下第一个jmp是什么跳到哪里 其实这是got表对应函数的got表,而且我们会发现0x201020的值是压栈命令的地址,其他地方为0,此时就想问: 一、got表与plt表有什么意义,为什么要跳来跳去? 二、got表与plt表有什么联系,有木有什么对应关系? 那么带着疑问先看答案,再去印证 我们要明白操作系统通常使用动态链接的方法来提高程序运行的效率,而且不能回写到代码段上。 在上面例子中我们可以看到, call scanf —> scanf的plt表 —>scanf的got表 ,至于got表的值暂时先不管,我们此刻可以形成这样一个思维

counting float digits (hw) C

不羁的心 提交于 2020-03-05 08:29:49
问题 I need to count digits from a float number and keep the number. I can use scanf() with %f or %c but not %s , and I can use getchar() . I can use getchar but I will loose the number. 回答1: Why will you lose the number with getchar ? Read characters with getchar until you hit whitespace/enter/end of input Collect them all into a single string Use strtod to make sure it's a valid floating point value Count digits in the string - either before, or after the point, whatever you need. If you're

【短期】文化课后的康复训练

旧巷老猫 提交于 2020-03-05 07:06:30
中考结束了嘛 然后由于D萎蛋了 所以前期是上午OI下午文化课晚上作业 提前把高一知识搞完这样停课比较稳 这几天先是简单题的康复训练 NOIP提高难度吧 然后中间穿插一些之前想补的题 嗯就这样,开始吧。 6.17 做了一下下面的小朋友【大雾 的题 还是很好做的嘛233 poj2437 有点辣鸡的贪心题 贪就完事了 处理边界有点麻烦 //Love and Freedom. #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #define ll long long #define inf 20021225 using namespace std; struct mud { int st,ed; bool operator<(const mud &x) { return st<x.st; } }m[10010]; int n,l; int main() { scanf("%d%d",&n,&l); for(int i=1;i<=n;i++) scanf("%d%d",&m[i].st,&m[i].ed); sort(m+1,m+n+1); int ans=0,lst=0; for(int i=1;i<=n;i++) { int tmp=max(lst,m[i].st);// printf("%d\n

Store hex input into int variable without using scanf() function in C

孤人 提交于 2020-03-05 06:58:06
问题 Pre-History: I had the issue, that the getchar() function did not get processed in the right way as there was not a request for any given input and the program just have continued processing further. I searched the internet about what this issue could be and found the information that if the scanf() function is implemented into a program before the getchar() function, the getchar() function does not behave in the right way, and would act like my issue was. Citation: I will bet you ONE HUNDRED

ccf201903-1跳一跳

百般思念 提交于 2020-03-05 01:36:37
#include <stdio.h> #include <string.h> #define N 40 int a[N]; int main(){ memset(a, 0, sizeof(a)); int t, sum = 0, count = 1; scanf("%d", &t); while(t){ if(t == 1){ sum++; count = 1; }else if(t == 2){ sum += 2*count; count++; } scanf("%d", &t); } printf("%d", sum); return 0; } 来源: CSDN 作者: WOSHILURENJI 链接: https://blog.csdn.net/WOSHILURENJI/article/details/104652851

Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

南笙酒味 提交于 2020-03-04 15:14:30
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一个queen了,问你有多少种方案,能够得到n点 题解 其实只用考虑三种情况,都考虑一下就好了,实在不行就暴力枚举…… 代码 #include<bits/stdc++.h> using namespace std; int n; int main() { scanf("%d",&n); if(n<=10||n>21)cout<<"0"<<endl; else if(n==20)cout<<"15"<<endl; else cout<<"4"<<endl; } B. Testing Pants for Sadness 题意 一共有n道题,每道题有a[i]个选项,每次答错这道题,就得重新答起。 现在问你最差的情况下,需要答多少次? 题解 答第i题失败,就会重新再答(i-1)次 代码 #include<bits/stdc++.h> using namespace std; const int maxn = 105; int n; int a[maxn]; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]);

hdu 2066 ( 最短路) Floyd & Dijkstra & Spfa

风格不统一 提交于 2020-03-04 07:32:32
http://acm.hdu.edu.cn/showproblem.php?pid=2066 今天复习了一下最短路和最小生成树,发现居然闹了个大笑话-----我居然一直写的是Floyd,但我自己一直以为这是Dijkstra---我居然一直把两个算法 记的是混的,还居然一直没有被别人发现,真是个大乌龙 好了,看看这道题,赤裸裸的最短路水题,首先来个Floyd的,把城市看成点,将连通的的点赋值为给定的时间,未连通的赋值为很大,这是个无向的关系 然后就是三个循环,以一个点为媒介,把每个点遍历一遍,比较找出点连通的最小值就行,稍微优化一点点就不会超时了 code 1 #include<cstdio> 2 #include<algorithm> 3 #define inf 1000000005 4 using namespace std; 5 int mp[1001][1001],q[1001]; 6 void jjc() 7 { 8 int i,j; 9 for (i=1;i<=1000;i++){ 10 for (j=1;j<=1000;j++){ 11 if (i==j) mp[i][j]=0; 12 else mp[i][j]=inf; 13 } 14 } 15 } 16 int min(int x,int y){ 17 if (x<y) return x; 18 else