C 输入一串数字,去掉其中含7的和能被7整除的数

C 输入一串数字,去掉其中含7的和能被7整除的数,每个数小于10000,数字个数小于100

输入例子:1,7,56,77,87,2,45,42,97,9977

输出:1,2,45

注意:输入个数不确定,所以不能够用整形数组处理,不能以判断整形数组元素是否等于\n为结束,因为数组是整形的,\n是字符型的,是输入不进去的

所以要用字符串来处理,先把用逗号相隔的所有整数取出来,然后再对这些数进行判断输出

#include<stdio.h>

#include<string.h>

void main()

{

char a[1000000];

int b[100],c[100];

int i,j,k,len,t,flag=0,len1=0;

k=0;len=0;t=0;

gets(a);

len1=strlen(a);

for(i=0,j=0;i<=len1;i++)

if(a[i]>=‘0‘&&a[i]<=‘9‘)

{

t=10*t+a[i]-‘0‘;

flag=1;

}

else if(flag==0)

continue;

else

{

b[j]=t;

j++;

len++;

t=0;

flag=0;

}

for(j=0,i=0;i<len;i++)

if(b[i]%7==0) continue;

else if(b[i]%10==7)continue;

else if((b[i]/10)%10==7)continue;

else if((b[i]/100)%10==7)continue;

else if((b[i]/1000)%10==7)continue;

else

{

c[j]=b[i];

j++;

}

for(i=0;i<j-1;i++)

printf("%d,",c[i]);

printf("%d\n",c[j-1]);

}

C 输入一串数字,去掉其中含7的和能被7整除的数,布布扣,bubuko.com

时间: 2024-08-06 16:02:06

C 输入一串数字,去掉其中含7的和能被7整除的数的相关文章

C 输入一串数字,去掉当中含7的和能被7整除的数

C 输入一串数字,去掉当中含7的和能被7整除的数,每一个数小于10000,数字个数小于100 输入样例:1,7,56,77,87,2,45,42,97,9977 输出:1,2,45 注意:输入个数不确定.所以不可以用整形数组处理.不能以推断整形数组元素是否等于\n为结束,由于数组是整形的.\n是字符型的,是输入不进去的 所以要用字符串来处理,先把用逗号相隔的全部整数取出来,然后再对这些数进行推断输出 #include<stdio.h> #include<string.h> void

Python 输入一串数字,对其排序或找寻max或min值

思考:当我们输入一串数字,使用什么函数?排序使用什么函数? 我使用的是Python 3 的input()函数,注意:input()函数的返回值始终是字符串 如果我们输入的是整数,我们需要int函数进行转化,如果是浮点型,则使用float函数转化.... 排序使用的是sort()函数,转换时还使用了map()函数,最大值利用的是max()函数,最小值是利用的min()函数,这些函数的具体用法我就不细说了,很简单 (但是这样有个问题就是输入的时候只能处理单个数字.....这个我在后面研究好后再来说一

hdu3652 数位dp(含13且被能被13整除的数)

http://acm.hdu.edu.cn/showproblem.php?pid=3652 B-number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2815    Accepted Submission(s): 1552 Problem Description A wqb-number, or B-number for sh

angular 输入框自动绑定输入长串数字出错

最近发现angular在使用input输入框的ng-model绑定scope变量的时候,发现,输入长串的数字将会出错.代码如下: <html> <head> <meta charset="UTF-8"> <title>test</title> <script type="text/javascript" src="../script/angular1.4.6.min.js">

输入一串数字和空格求和C和C++实现

编写一个程序,要求用户输入一连串的数字和任意空格(作为分隔符),求和输出 #include <stdio.h> int main(int argc, const char *argv[]) { int num = 0,sum = 0; char ch; while((ch = getchar()) != '\n') { if(ch != ' ') { num = num*10+ch-'0'; } if(ch == ' ') { sum = sum +num; num = 0; } } prin

输入一串数字找出其中缺少的最小的两个数

Description There is a permutation without two numbers in it, and now you know what numbers the permutation has. Please find the two numbers it lose. Input There is a number Tshows there are T test cases below. (T<=10)  For each test case , the first

输入一串随机数字,然后按千分位输出。

比如输入数字串为"123456789",输出为123,456,789 #!/bin/bash read -p "输入一串数字:" num v=`echo $num| sed 's/[0-9]//g'` if [ -n "$v" ] then     echo "请输入纯数字."     exit fi length=${#num} #表示num字符串的长度 len=0 sum='' for i in $(seq 1 $leng

ACM找出一串数字是否能被分成两部分使其中一部分全部为负数,加上另一部分可以为0

Description Most financial institutions had become insolvent during financial crisis and went bankrupt or were bought by larger institutions, usually by banks. By the end of financial crisis of all the financial institutions only two banks still cont

vc 文字转换到机内码,输入汉字和数字, 输出一串16进制码(数字-〉ASII码,汉字—〉国标码)

// 可以用,此程序实现的是是文字转换到机内码.机内码=国标码+8080H,不过学习了. //此程序是利用汉字在机器内输出就是机内码的原理,直接保存的,其实挺简单. //输入一串汉字和数字的混合字符, 经过程序转换, 对应输出一串16进制码(数字-〉ASII码,汉字—〉国标码) CString temp; GetDlgItemText(IDC_EDIT1,m_hanzi);//将汉字保存到变量m_hanzi unsigned char *b=new unsigned char[m_hanzi.G