新生42
数字反转
数字反转:
题目描述
给定一个整数,请将该数各个位上数字反转得到一个新数。新数也应满足整数的常见形式,即除非给定的原数为零,否则反转后得到的新数的最高位数字不应为零。
输入
输入共 1 行,一个整数N。-1,000,000,000 ≤ N≤ 1,000,000,000
输出
输出共 1 行,一个整数,表示反转后的新数。
样例输入 Copy
123
样例输出 Copy
321
不想说啥了。写的挺长...
#include<iostream> #include<algorithm> using namespace std; int main(){ string ch; cin>>ch; if(ch[0]=='-') reverse(ch.begin()+1,ch.end()); else reverse(ch.begin(),ch.end()); if(ch[0]=='-') { if(ch[1]!='0') cout<<ch; else { int i=1; while(ch[i]=='0') i++; cout<<"-"; for(int j=i;j<ch.size();j++) cout<<ch[j]; } } else { if(ch[0]!='0') cout<<ch; else { int i=0; while(ch[i]=='0') i++; for(int j=i;j<ch.size();j++) cout<<ch[j]; } } }
题目描述
The word internationalization is sometimes abbreviated to i18n. This comes from the fact that there are 18 letters between the first i and the last n.
You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
Constraints
3≤|s|≤100 (|s| denotes the length of s.)
s consists of lowercase English letters.
You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.
Constraints
3≤|s|≤100 (|s| denotes the length of s.)
s consists of lowercase English letters.
输入
Input is given from Standard Input in the following format:
s
s
输出
Print the abbreviation of s.
样例输入 Copy
internationalization
样例输出 Copy
i18n
这个题nnd,我的问题吗,我一开始一直以为是第一个i和最后一个n之间有多少个数字,每一次修改最后答案都只对17,后来才发现....第一个数和最后一个数之间有多少个单词,再输出开头和结尾就行了...
没啥好说的了
We have a sequence of length N, a=(a1,a2,…,aN). Each ai is a positive integer.
Snuke's objective is to permute the element in a so that the following condition is satisfied:
For each 1≤i≤N−1, the product of ai and ai+1 is a multiple of 4.
Determine whether Snuke can achieve his objective.
Constraints
2≤N≤105
ai is an integer.
1≤ai≤109
Snuke's objective is to permute the element in a so that the following condition is satisfied:
For each 1≤i≤N−1, the product of ai and ai+1 is a multiple of 4.
Determine whether Snuke can achieve his objective.
Constraints
2≤N≤105
ai is an integer.
1≤ai≤109
输入
Input is given from Standard Input in the following format:
N
a1 a2 … aN
N
a1 a2 … aN
输出
If Snuke can achieve his objective, print Yes; otherwise, print No.
样例输入 Copy
3
1 10 100
样例输出 Copy
Yes
提示
One solution is (1,100,10).
意思就是重新排列使相邻的两个数相乘可以被4整除
ac85的代码:....
#include<iostream> using namespace std; int main(){ int n,t,j=0,o=0,p=0,x=0; cin>>n; for(int i=0;i<n;i++) { cin>>t; if(t%2==1) j++; else if(t%4==0) p++;//既可以被4整除又一定是偶数 else if(t%2==0&&t%4!=0) x++; } if(j==1) { if(p>=1) cout<<"Yes"<<endl;//可以放两端 else cout<<"No"<<endl; } else if(j==2)//两端 { if(p==1&&x>=2||p>1) cout<<"Yes"<<endl; else cout<<"No"<<endl; } else if(j>2)//中间 { j-=2; if(p>=j+1&&x%2==0) cout<<"Yes"<<endl; else cout<<"No"<<endl; } else if(j==0) cout<<"Yes"<<endl; }
到后面越写越乱....
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具