View Code of Problem 101

#include<stdio.h>
#include<string.h>
int main()
{
	char s[50];
	
	while(gets(s)!=NULL)
	{
		
		int le_s=strlen(s);
		int k=le_s-(le_s/5);//去掉“,”,剩下的数字个数k 
		int y=k%3; //多出来的数字个数y 
		
		int y_t=0;
		int k_t=0; //t累加,直到k 
		
		int i=0;
		
		if(y!=0)
		{
			for(i;y_t<y;i++)
	    	{
	    		if(s[i]>='0'&&s[i]<='9') 
	    		{
	    			printf("%c",s[i]);
	    			y_t++;
				}	
		    }
			printf(",");
		}
		for(i;i<le_s;i++)
		{
			if(s[i]>='0'&&s[i]<='9')
			{
				printf("%c",s[i]);
				k_t++;
			}
			if(k_t%3==0)
			{
				if(k_t!=(k-y))
					printf(",");
				else
					printf("\n");
			}				
		}
	}
	
	return 0;
}

Double click to view unformatted code.


Back to problem 101