C语言:一个给定的字符串,提取其中的数字,连在一起构成一个整数,再乘以513,就是结果 用c语言提取字符串中的数字
C\u8bed\u8a00\u95ee\u9898\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u4efb\u610f\u5b57\u7b26\u4e32\uff0c\u63d0\u53d6\u51fa\u5176\u4e2d\u6240\u5305\u542b\u7684\u6574\u6570\u3002\u3000\u3000\u67e5\u627e\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u5b57\u5e76\u8fd4\u56de\u5176\u4e2a\u6570\uff1a
#include int main(void){char str[1000];int i, count, a[100];int p, q, r;int tmp;gets(str);r = 0;count = 0;while(1){while(str[r] && (str[r]'9'))r++;//\u8df3\u8fc7\u975e\u6570\u5b57 if(str[r]){p = r;//p\u6307\u5411\u6570\u5b57\u5b50\u4e32\u5f00\u5934q = r + 1;//q\u5bfb\u627e\u6570\u5b57\u4e32\u7ed3\u5c3e a[count] = str[r]-'0';while(str[q]>='0' && str[q]<='9'){a[count] = 10*a[count]+(str[q]-'0');q++;}r = q;//\u65b0\u8d77\u70b9count++; }elsebreak; }printf("\u5171\u8ba1 %d \u4e2a\u6574\u6570\uff1a", count);for(i=0; i<count; i++)printf("%d ", a[i]);printf("\n");return 0;}
\u7528c\u8bed\u8a00\u63d0\u53d6\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u5b57\u7684\u64cd\u4f5c\u5982\u4e0b\uff1a
1\u3001\u9996\u5148\u6253\u5f00visual studio\u8f6f\u4ef6\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u7684c\u8bed\u8a00\u6587\u4ef6\uff0c\u5982\u4e0b\u6240\u793a\u3002
2\u3001\u7136\u540e\u5bfc\u5165C\u8bed\u8a00\u6587\u4ef6\u9876\u90e8\u7684\u5e93\u5185\u5bb9\uff0c\u5982\u4e0b\u6240\u793a\u3002
3\u3001\u7136\u540e\u4f7f\u7528scanf\u51fd\u6570\u63a5\u6536\u7528\u6237\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u3002
4\u3001\u7136\u540e\u4f7f\u7528printf\u51fd\u6570\u6253\u5370\u7528\u6237\u8f93\u5165\u3002
5\u3001\u8fd0\u884c\u7a0b\u5e8f\u540e\uff0c\u5f39\u51fa\u4e0b\u56fe\u6240\u793a\u7684\u547d\u4ee4\u754c\u9762\uff0c\u81ea\u52a8\u63a5\u6536\u8f93\u5165\u5185\u5bb9\uff0c\u6309\u539f\u6837\u8f93\u51fa\u3002
6\u3001\u6700\u540e\uff0c\u5982\u679c\u63a5\u6536\u5230\u5176\u4ed6\u7c7b\u578b\uff0c\u4f8b\u5982\u6574\u6570\uff0c\u5219\u9700\u8981\u5c06\u8be5\u7c7b\u578b\u66f4\u6539\u4e3aint\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff0cscanf\u4e2d\u7684\u63a5\u6536\u7c7b\u578b\u5c06\u53d8\u4e3ad%\uff0c\u5e76\u63d0\u53d6\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u5b57\u3002
#include <stdio.h>
#define N 100
int main()
{
int i;
long r;//要注意结果可能会超出普通整形范围
char s[N];
scanf("%s",s);
i=0;
r=0;
while(s[i]!='\0'){
if(s[i]>='0'&& s[i]<='9')
r=r*10+(s[i]-'0');
++i;
}
// r*=513;
printf("输入串:s=%s
提取数字:r=%ld
结果:r*513=%ld
",s,r,r*513);
return 0;
}
#include<stdio.h>
void main() { char str[31],*p; int a,b,n,i;
scanf("%d",&n);
for ( i=0;i<n;i++ ) {
gets(str); p=str; a=0;
while ( *p ) {
if ( *p>='0' && *p<='9' ) { a*=10; a+=*p-'0'; }
p++;
}
b=a*513;
printf("%d
",b);
}
}
绛旓細='\0'){ if(s[i]>='0'&& s[i]<='9') r=r*10+(s[i]-'0'); ++i; } // r*=513; printf("杈撳叆涓:s=%s\n鎻愬彇鏁板瓧:r=%ld\n缁撴灉:r*513=%ld\n",s,r,r*513); return 0;}
绛旓細鏌ユ壘瀛楃涓涓殑鏁板瓧骞惰繑鍥炲叾涓暟锛歩nclude <stdio.h>int main(void){char str[1000];int i, count, a[100];int p, q, r;int tmp;gets(str);r = 0;count = 0;while(1){while(str[r] && (str[r]<'0' || str[r]>'9'))r++;//璺宠繃闈炴暟瀛 if(str[r]){p = r;//p鎸囧悜...
绛旓細缁欏畾涓涓暟瀛楀瓧绗︿覆锛屾妸杩欎釜涓查噷杈圭殑杩炵画鏁板瓧鎻愬彇鍑烘潵鏀惧埌鍙﹀涓涓暣鍨嬫暟缁勪腑涓涓崟鍏冧腑锛歩nclude<iostream> include<string> using namespace std;void tiqu(char*a,int*b){ int j=0;bool key=false;for(int i=0;i<strlen(a);i++){ if(a[i]>='0'&&a[i]<='9'){ if(key)b[j] ...
绛旓細string[] split = url.Split('.');string result = split[1];Label1.Text = result;
绛旓細鐢 sscanf() ;渚嬪锛歝har str[80]="1101";int a[4];sscanf(str,"%1d%1d%1d%1d",&a[0],&a[1],&a[2],&a[3]);
绛旓細缁欎綘鍐欎竴涓畝鍗曠殑鍚э紝鍐欏緱澶嶆潅浜嗭紝涔熶笉濂斤紝涓婃缁欎綘鍐欑殑涓涓紝閲囩敤浜嗕竴浜涚壒娈婃柟娉曪紝杩樹笉濡傜洿鎺ュ啓鐨勶紝鏅曪紒瀛绋嬪簭锛鍏抽敭鏄鏂规硶锛乿oid substr(char *str1,char *str2,int start,int end){ int ii;for (ii=start;ii<=end;ii++)str1[ii-start]=str2[start-1];str1[ii-start]='\0';...
绛旓細include <stdio.h>int main(int argc, char const *argv[]){ char line[1024] = "\0"; // <--- 鏈澶1023涓瀛楃锛鍙寜闇瑕佷慨鏀 int i; gets(line); // <--- 璇诲叆涓琛瀛楃涓诧紝瀛樺叆鏁扮粍line涓 for (i = 0; i < sizeof(line); ++i) { // <-- 鎸夊瓧绗﹂愪釜鍒ゆ柇 ...
绛旓細鍦C璇█涓瀛楃涓鏈変袱绉嶈〃绀烘柟娉曚竴绉嶆槸瀛楃鎸囬拡 锛屼竴绉嶆槸瀛楃鏁扮粍銆俢onst char *str = "helllo world"; //瀛楃鎸囬拡鎸囧悜瀛楃涓 char str[] = "hello world"; //瀛楃鏁扮粍淇濆瓨瀛楃涓层傚瓧绗︽寚閽堬紝鍙互鐪嬩綔瀛楃鏁扮粍锛屼袱鑰呴兘鍙互鐢ㄧ淮鏁版潵涓涓竴涓殑鎿嶄綔瀛楃銆傜ず渚嬪涓嬶細include <stdio.h>#include <...
绛旓細鎸変綘杩介棶鐨勮姹傛敼浜嗕竴涓嬨傝繖娈典唬鐮佽兘鎶婇敭鐩樿緭鍏ョ殑鐗瑰畾瀛楃涓鍚庨潰鍙屽紩鍙峰唴鐨勬枃瀛鎻愬彇鍑烘潵瀛樺叆XYZ.txt鏂囦欢涓傚湪鎻愬彇杩囩▼涓护闄や簡婧愭枃浠朵腑鐨'\n'鍜' '銆備緵鍙傝冣︹nclude "stdio.h"// include "string.h"// include "stdlib.h"// void main(void){ FILE *pR,*pW;char CoStr[20],ln,ch,...
绛旓細chara,ch,str[80];scanf