if(b==0) return a; llong r=a%b;
while(r>0) { a=b; b=r; r=a%b; } return b; }
int main() {
while(scanf(\{
if(a==0&&b==0&&c==0) break; t=gcd(a,b); if(t==0){
if(c==0) printf(\ }
else {
if(c%t == 0) printf(\ else printf(\ } }
return 0; }
19.有多少个1?
Acceteped : 413 Submit : 875
Time Limit : 1000 MS Memory Limit : 65536 KB
Description
计算机中存储的整数都是按补码的型式,一个32位有符号整数的补码的定义为:如果x>=0,则x的补码等于x的二进制表示;如果x<0,那么x的补码为2^32+x的二进制表示。请根据给定的整数,求出它的补码包含有多少位为1。 输入
每行一个样例,为一个整数(可以用int表示)。 输出
每行输出一个对应样例的结果。
Sample Input 1 0 -1
36
Sample Output 1 0 32
Source Code
Problem: 1059 User: 2009551233 Memory: 952K Time: 0MS
Language: G++ Result: Accepted
Source Code
#include
int count(__int64 n) {
int sum=0;
while(n>0) { if(n%2==1) sum++; n/=2; } return sum; }
int main() {
__int64 n;
while(scanf(\{
if(n>0) printf(\ else if(n==0) printf(\ else printf(\}
return 0; }
20.合法的整数
Acceteped : 189 Submit : 638
Time Limit : 1000 MS Memory Limit : 65536 KB
37
Description
C语言中的10进制整数常量定义如下(不是严格的C定义,有简化):
1) 常量的开头可以有“+”或“-”号,也可以没有;
2) 至少有一位数字位,除非数字为0,否则第一个数字必须为1到9的数字;
3) 如果有符号的话,符号与数字之间可以有0个或多个空格。
4) 常量的前后可能会有若干空格。
请写一个程序判断给定的整数是否符合这个定义。 输入
每个样例一行,每行表示一个整数,字符长度不超过20; 输出
每行输出一个样例的结果,如果符合定义输出“Yes”,否则输出“No”
Sample Input -123 5F
Sample Output Yes No
Source Code
Problem: 1060 User: 2009551233 Memory: 856K Time: 0MS
Language: C++ Result: Accepted
Source Code
#include
38
{
bool flag=false; while(gets(s)) {
flag=true; int i=0;
while(s[i]==' ') {
i++; }
if(s[i]=='+'||s[i]=='-') {
while(s[++i]==' ') {; }
int j=i;
while(s[j]!=' '&&s[j]!='\\0') {
j++; }
int m=j;
while(s[m]!='\\0') {
if(s[m]!=' ') {
// cout<<\ flag=false; }
m++; }
// cout<
if(s[i]<'0'||s[i]>'9') flag=false; } else {
// cout<<\ if(s[i]>'9'||s[i]<='0') {
// cout<<\ flag=false;
39
}
for(int k=i+1;k if(s[k]>'9'||s[k]<'0') { // cout<<\ flag=false; } } } } else{ int j=i; while(s[j]!=' '&&s[j]!='\\0') { j++; } int m=j; while(s[m]!='\\0') { if(s[m]!=' ') { // cout<<\ flag=false; } m++; } // cout< if(s[i]<'0'||s[i]>'9') flag=false; } else { // cout<<\ if(s[i]>'9'||s[i]<='0') { // cout<<\ flag=false; } for(int k=i+1;k { 40