View Code of Problem 101

/*现在,请你帮我写一个程序:将那些按“万位”来分隔的数字转换成按“千位”来分隔,
让欧美的用户使用更加方便。将其看作字符串*/
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
	char a[100],b[100];
	int i,j,count;
	while(scanf("%s",a)!=EOF){
		count=0;
		j=0;
		for(i=strlen(a)-1;i>=0;i--){
			if(a[i]==',')continue;

			count++;
			if(count%3==0&&count!=0){//避免输入100   出现,100的情况 
				b[j++]=',';
			}
			b[j++]=a[i];
		//	count++;
		}
	for(i=j-1; i>=0; i--) {
			printf("%c",b[i]);
		}
		printf("\n");	
	}
} 

Double click to view unformatted code.


Back to problem 101