Example #1
0
	// Given a string, compute recursively( no loops ) the number of lowercase 'x' chars in the string
	int countX( string str )
	{
		if( str.length() == 0 )
			return 0;

		string next = str.substr( 1, str.length() );

		return str.at( 0 ) == L'x' ?
			1 + countX( next ) : countX( next );
	}
Example #2
0
int main() {

    FILE *ifp;
    ifp = fopen("golf.txt", "r");
    char grid[SIZE][SIZE]; 
    char line[SIZE+1];
    int i,j;
	
    // Loop through reading each line of the input file and store each
    // character in grid.
    for (i=0; i<SIZE; i++) {
	fscanf(ifp, "%s", line);
	for (j=0; j<SIZE; j++)
	    grid[i][j] = line[j];
		
    }
		
    // Find s in the grid, store the location in x,y.
    int x=0,y=0;
    for (i=0; i<SIZE; i++) {
	for (j=0; j<SIZE; j++) {
	    if (grid[i][j] == 's') {
	        x = i;
	        y = j;
	        break;
            }
	}
    }
	
    // Run our floodfill and output the appropriate information.	
    floodfill(grid,x,y);
    printf("%d\n",countX(grid));
    printf("$%d 000\n", 50*countM(grid));
	
    fclose(ifp);
	
    system("PAUSE");
    return 0;
}